简体   繁体   English

科学记数法 - .NET 中的错误?

[英]Scientific Notation - bug in .NET?

Yeah I know it's hard to believe - bug in .NET?是的,我知道这很难相信 - .NET 中的错误? But run this code in the command line app:但在命令行应用程序中运行此代码:

decimal x;

x = decimal.Parse("3.E-2", NumberStyles.Float);
Console.WriteLine(x);

x = decimal.Parse("5.72e9", NumberStyles.Float);
Console.WriteLine(x);

x = decimal.Parse("3.E−2", NumberStyles.Float);
Console.WriteLine(x);

I'm getting exception during the last parse.在最后一次解析期间我遇到了异常。 Saying:说:

System.FormatException : Input string was not in a correct format.

The value for the first and last parse are exactly the same.第一次和最后一次解析的值完全相同。 Tested on two different x64 machines compiled toward .NET 3.5 and 4.在针对 .NET 3.5 和 4 编译的两台不同 x64 机器上进行了测试。

Any idea what is going on?知道发生了什么吗? Any work-around?任何解决方法?

The first and 3rd are not exactly the same.第一个和第三个不完全一样。

in the 3rd you have a "longer" - sign, as a result it doesnt know what to do with it.在第三个你有一个“更长的” - 标志,结果它不知道如何处理它。 Therefore you would need to check for that and replace it with the standard minus sign因此,您需要检查并用标准减号替换它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM