“At 7-Eleven, you’d take a penny from the tray, right? Well those are whole pennies! I’m just talking about fractions of a penny here, OK? But w

The Deadly Consequences of Rounding Errors

submited by
Style Pass
2024-10-09 22:00:04

“At 7-Eleven, you’d take a penny from the tray, right? Well those are whole pennies! I’m just talking about fractions of a penny here, OK? But we do it from a much bigger tray, and we do it a couple million times.” That’s how Peter Gibbons (Ron Livingston) explains his penny-shaving scheme in Office Space.* Penny-shaving is a plot point in Superman III, too—in both movies, characters make huge amounts of money by taking advantage of the fact that numbers need to be shortened to two decimal places in order to function as currency, in dollars and cents.

Computer code can handle this problem in many ways, including the command round(), which rounds to the nearest cent, or floor(), which just cuts off all the extra decimal places. For example, an after-tax salary computation of $145.459 would normally be rounded to $145.46; in a penny-shaving scheme, it would be floored to $145.45 instead. Such a small change is generally imperceptible to people in their paycheck, but when millions or billions of such fractional cents are stolen, it adds up.

Sometimes those fractional cents aren’t stolen—they simply vanish. In the early 1980s, a new stock index at the Vancouver Stock Exchange tracked a steady and mysterious loss in value. An investigation revealed that floor() was being used instead of round(), with the lost fractions of cents accumulating to almost a 50 percent loss of value in 22 months. The programming mistake was finally fixed; the index closed around 500 on a Friday and reopened the following Monday at over 1,000, the lost value restored.

Leave a Comment