C#浮点数问题示例:
解决方案是使用【decimal】
//双浮点数计算失精问题示例 double x = 300.2; double y = 300; Console.WriteLine("double计算"+(x - y)); //双浮点数计算失精问题解决示例 decimal d1 = decimal.Parse("300.2"); decimal d2 = decimal.Parse("300"); Console.WriteLine("decimal计算"+(d1 - d2));
对比效果: