Floating-point rounding left two state overtime calculators a penny off in their totals
A developer building 51 state overtime calculators with shared JavaScript found that totals on two pages were one cent too low. The cause was floating-point arithmetic, not the state pay rules, since binary storage of decimals like 0.1 can push values across rounding boundaries. Summing already-rounded line items allowed the error to accumulate, so the developer changed the code to add exact values and round once at the end. The fix also moved money calculations to integer cents and added manual checks against worked examples for each state page. The developer concluded that rounding should happen once, as late as possible, and never feed into further calculations.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in