in reply to Why is Zero not 0?
For instance, 0.1 can't be represented exactly in an IEEE binary float (as used by the majority of CPUs that perl runs on). This means that you generally can't rely on any math operation involving floating point numbers to give you an exact result.
Either use rational numbers (see Math::BigRat) or round the results (and note that many standard rounding strategies (like sprintf "%d" and sprintf "%0f") give results that don't conform to the "naive highschool" method of rounding - for more or less good reasons). See also Math::Round.
update: note that "really integer" floats (perl uses doubles for floats) are exact within a very large range (a range larger than native integers on my machine at least), so xxxx.0 is generally exact. I suspect the numbers in your post aren't really the numbers used in the calculations.
update 2: this is the standard text to bully people with
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is Zero not 0?
by apl (Monsignor) on Feb 21, 2008 at 18:58 UTC |