Multiplying a double value by 100.0 introduces rounding errors?

前端 未结 8 1037
后悔当初
后悔当初 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 08:10

    You should really use decimal for money calculations.

    ((int)(580.55m * 100.0m)).ToString().Dump();
    
    0 讨论(0)
  • 2020-12-19 08:14

    Decimal has more precision than a double. Give decimal a try.

    http://msdn.microsoft.com/en-us/library/364x0z75%28VS.80%29.aspx

    0 讨论(0)
提交回复
热议问题