Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi every one I want to compute some formula but when i using

C#
object Result = new DataTable().Compute(Formul, string.Empty);


for example this formula (-1163142499 - 281259084 - 4700000 - 848996756)
i get this message which the number is too large or to small for int32 how can i use this
methods by larger data types.
thanks.
Posted
Comments
[no name] 4-Jul-14 3:05am    
You can use Int64
[no name] 4-Jul-14 3:21am    
BigInteger

Why are you trying to use DataTable.Compute as an expression evaluator?
Why not use an actual expression evaluator?

There are Loads of them on this site alone, that you can use, or modify to fit your needs:
Google List for Codeproject[^]
The top two are good (though the first is rather old):
Runtime C# Expression Evaluator[^]
A Tiny Expression Evaluator[^]
 
Share this answer
 
Comments
MohsenGolmehr 5-Jul-14 0:42am    
Hi Thanks for your answers.
the reason i am using this method is i do not want use complex solution for a simple problem
because i have lots of complex problem on this application and calculating is not much complexer than example it is just (Plus , Mines , Parenthesis , Multiplication ,Divide)
I Tried so many test on Sql server And I found this
when I write this Command

SQL
SELECT SUM(-1163142499 - 281259084 - 4700000 - 848996756)


I get this error

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.


And then I write this

SQL
SELECT SUM(10000000000000000000000 + -1163142499 - 281259084 - 4700000 - 848996756) AS Res


Res = 9999999999997701901661

I get Answer But I must Reduce it by (10000000000000000000000)

I dont know whats going on but it solved My problem.

Thanks you All.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900