in reply to Re^2: 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)
in thread 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)

So can I avoid it somehow?

Yes, multiply everything by 100 (i.e. deal with cents instead of dollars), and divide by 100 (i.e. convert to dollars) when you print. You won't have the problem, because it doesn't occur for numbers with no decimals, unless they get really big (> 2 billion on a 32 bit system).

>perl -e "$a=0; $a += 0.10 for (1..60); print($a, $/);" 5.99999999999999 >perl -e "$a=0; $a += 10 for (1..60); print($a/100, $/);" 6
  • Comment on Re^3: 4253.95 + 0.9 = 4254.84999999999 (need help to interpret internals)
  • Download Code