双倍变量的值在乘以100后不精确

时间:2015-04-29 11:04:24

标签: c#

我从Gridview(Devexpress XtraGrid)获取变量的值。当我将值乘以100时,它会失去精度。这是我使用

的代码
//Value written on the cell is 0.285
double Width = double.Parse(grdvwDimension.GetRowCellValue(0, "Width");
//Now the value of Width = 0.285

Width = Width * 100;
//Now the value of Width = 28.499999999999996
//It should have been 28.5

我在另一个项目中遇到过这种问题,但我发现我应该使用float或double一直彻底解决项目,而不是两者。

我尝试了一些其他值,有时它可以正常工作(0.385变为38.5),有时它不会(0.274变为27.400000000000002)。

我检查了列的数据类型是什么,它是double。我在代码中使用了double。

那么,可能是什么问题?

0 个答案:

没有答案
相关问题