如何在c#中计算巨大的算术字符串表达式 [英] how to compute huge arithmetic string expression in c#

查看:64
本文介绍了如何在c#中计算巨大的算术字符串表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我想计算一些公式,但是当我使用



 对象结果=  new  DataTable()。计算(Formul, string  .Empty); 





例如此公式( - 1163142499 - 281259084 - 4700000 - 848996756)

i得到这个数字太大或者对于int32来说很小的消息我怎么能用更大的数据类型来使用这个

方法。

谢谢。

解决方案

为什么要尝试使用DataTable.Compute作为表达式求值程序?

为什么不使用实际的表达式求值程序?



仅在此网站上有一些负载,您可以使用或修改以满足您的需求:

Codeproject的Google列表 [ ^ ]

前两个是好的(虽然第一个相当陈旧):

运行时C#Expression Evaluator [ ^ ]

微小的表达评估器 [ ^ ]


我在Sql server上尝试了这么多测试我发现这个

当我写这个命令时



  SELECT  SUM (-1163142499  -   281259084   -   4700000   -   848996756 





我收到此错误



Msg 8115 ,Level 16,State 2,Line 1

将表达式转换为数据类型int的算术溢出错误。




然后我写这个



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





Res = 9999999999997701901661



我得到答案但我必须减少它(10000000000000000000000) )



我不知道发生了什么但它解决了我的问题。



谢谢大家。


Hi every one I want to compute some formula but when i using

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.

解决方案

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[^]


I Tried so many test on Sql server And I found this
when I write this Command

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

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.


这篇关于如何在c#中计算巨大的算术字符串表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆