Calculator Floating Point Error Corrections

Calculator Floating Point Error Corrections
0

#1

For the JavaScript Calculator challenge, how do you guys correct for floating point errors?

If you just round, wouldn’t you need to round down by a different amount of decimal places depending on the calculation being done?

How do people normally fix this?


#2

I limited the number of digits that my calculator could display so the results got truncated. There are no rounding errors if no one can see them. There are other strategies, such as multiplying both numbers by 100 before multiplying/dividing, then dividing the result by 10,000.

When it comes to numbers that matter (like finances), math doesn’t get done in the browser. User events get sent from the browser and the sensitive math is done at the server. Everything else gets fudged because who cares?