views:

60

answers:

1

Hello All,

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.

A: 

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...

bwawok
thanks for the reply
collegian