开发者

How to check for rounding off errors?

This may be a dumb question to ask: While using float there is some rounding off done for decimal places, how to check for rounding off errors preferably in java or C? Any suggestions will开发者_运维知识库 be greatly appreciated.


Well, you could do the operation in something with NO rounding, and compare the results. For example, in java you could use Big Decimal to do an operation after you did it with float... and see if you end up with the same number.

A better question, is why do you want to do this? Float will often do weird rounds, you don't want to use it anywhere you need precision (i.e. with a banking transaction). In that case, use Big Decimal. But if you just want to represent a 3D point on the screen, 1.5 rounding to 1.499997 won't change anything...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜