double.tostring()行为不一致

发布于 2025-02-09 20:11:08 字数 815 浏览 1 评论 0原文

IM将字符串转换为double,然后将转换的值分开,如下所示。

double.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double convertedValue);
var splitValue = convertedValue.ToString(CultureInfo.InvariantCulture).Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

从Nunit TestCase和应用程序运行时,上述代码段的行为是不同的。

例如:

如果StringValue =“ 0.0000000000000000000000000000003402823499999999”“

从N-Nunit运行时:

         convertedValue = 3.4028234999999987E-21            
         splitValue[0]= "3";
         splitValue[1] = "4028235E-21"

从应用程序运行时,

        convertedValue = 3.40282349999999E-21                
        splitValue[0]= "3";
        splitValue[1] = "40282349999999E-21"            

我想了解这种行为的原因吗?

Im converting a string to double and then splitting the converted value as shown below.

double.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double convertedValue);
var splitValue = convertedValue.ToString(CultureInfo.InvariantCulture).Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

The behavior of the above code snippet is different when run from Nunit testcase and from the application.

for example:

if stringValue="0.000000000000000000003402823499999999""

when run from n-nunit:

         convertedValue = 3.4028234999999987E-21            
         splitValue[0]= "3";
         splitValue[1] = "4028235E-21"

When run from the application

        convertedValue = 3.40282349999999E-21                
        splitValue[0]= "3";
        splitValue[1] = "40282349999999E-21"            

I wanted to understand the reason for this behavior ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文