小编Iva*_*sky的帖子

.NET C#float.Parse将不同的结果返回给double.Parse

一些更有经验的人可以解释我今天发现的这个奇怪错误吗?当我用C#脚本加载表数据时,我得到了奇怪的数量.

事实证明问题是类似功能的不同输出:

string amount_in_string = "1234567,15";
double amount_in_double = double.Parse(amount_in_string);
float amount_in_float = float.Parse(amount_in_string);

//amount_in_double = 1234567.15;
//amount_in_float = 1234567.13;
Run Code Online (Sandbox Code Playgroud)

当float和double是相似类型(浮点)时,为什么我会得到这样的结果.精确度可以与这些少量产生差异吗?

.net c# floating-point precision types

6
推荐指数
1
解决办法
1175
查看次数

标签 统计

.net ×1

c# ×1

floating-point ×1

precision ×1

types ×1