Why is my number being rounded incorrectly?

后端 未结 5 1109
攒了一身酷
攒了一身酷 2021-01-18 05:00

This feels like the kind of code that only fails in-situ, but I will attempt to adapt it into a code snippet that represents what I\'m seeing.

float f = myFl         


        
5条回答
  •  萌比男神i
    2021-01-18 05:35

    Because floating point variables are not infinitely accurate. Use a decimal if you need that kind of accuracy.

    Different rounding modes may also play into this issue, but the accuracy problem is the one you're running into here, AFAIK.

提交回复
热议问题