Multiplying a double value by 100.0 introduces rounding errors?

前端 未结 8 1062
后悔当初
后悔当初 2020-12-19 07:22

This is what I am doing, which works 99.999% of the time:

((int)(customerBatch.Amount * 100.0)).ToString()

The Amount value is a double. I

8条回答
  •  臣服心动
    2020-12-19 07:59

    You could use decimal values for accurate calculations. Double is floating point number which is not guaranteed to be precise during calculations.

提交回复
热议问题