3 回答

TA贡献1846条经验 获得超7个赞
0.1
decimal
0.1
12.34
1 * 101 + 2 * 100 + 3 * 10-1 + 4 * 10-2
2
: 10.01
1 * 21 + 0 * 20 + 0 * 2-1 + 1 * 2-2
1/3
0.3333333…
1/10
0.000110011001100…
.

TA贡献1828条经验 获得超4个赞
double
Double
double
Double
x
0.1
0.100000001
if (Math.Abs(x - 0.1) < 0.0000001){ ...}

TA贡献1772条经验 获得超8个赞
Math.Abs
X-Y
value
public static class DoubleExtensions { const double _3 = 0.001; const double _4 = 0.0001; const double _5 = 0.00001; const double _6 = 0.000001; const double _7 = 0.0000001; public static bool Equals3DigitPrecision(this double left, double right) { return Math.Abs(left - right) < _3; } public static bool Equals4DigitPrecision(this double left, double right) { return Math.Abs(left - right) < _4; } ...
ToString
x
y
if(x.Equals4DigitPrecision(y))
- 3 回答
- 0 关注
- 440 浏览
添加回答
举报