in reply to (Ovid) Re: Unwanted implicit conversion to float
in thread Unwanted implicit conversion to float
I see just a (maybe null) risk in the fact that you still add 2 floating numbers, even if $1 has been rounded to 2 digits after the decimal point. So something weird can still happen with the result. After all turnstep's original code only added such numbers. So you could end up every now and then with "long numbers".
Doing $val= sprintf( "%.2f", $val + $1); removes the problem, $val is _always_ rounded properly. The cleanest way is of course to keep $val as is and to round it only when printing it.
This may just be nitpicking but as I have no idea of the conditions that create the problem and it is probably quite hard to reproduce, I would not take any chance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Unwanted implicit conversion to float
by tye (Sage) on Mar 12, 2001 at 23:32 UTC | |
by mirod (Canon) on Mar 12, 2001 at 23:54 UTC |