in reply to How to determine whether a number has a decimal component?
Because of limitations on integer vs floating point representations in computing, comparing $number vs int($number) may cause problems with integer overflow (use bigint may alleviate this). For input data, checking for a decimal point should work; for the results of computation, well, remember that on most computers (1.0/3.0) * 3.0 won't return exactly 1, but something like 0.99999…, so, as mentioned by others, you'll have to check for $number - int($number) ≤ &epsilon. You'll also have to realize that it won't always work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to determine whether a number has a decimal component?
by Xenofur (Monk) on Jan 04, 2009 at 18:38 UTC | |
by swampyankee (Parson) on Jan 04, 2009 at 21:34 UTC | |
by Xenofur (Monk) on Jan 04, 2009 at 21:58 UTC | |
by swampyankee (Parson) on Jan 04, 2009 at 22:40 UTC |