in reply to strange rounding behaviour
That code doesn't seem to exhibit the strange behavior you see when sprintf for rounding.#round $num to 2 decimal places $rounded = int(0.5+$num*100)/100;
In case you care about performance, the INT version I describe is more than 2.5 times as fast as the sprintf version:
Benchmark: running RoundINT, RoundSPRINTF, each for at least 3 CPU seconds... RoundINT: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 7753.02/s (n=24422) RoundSPRINTF: 3 wallclock secs ( 3.21 usr + 0.00 sys = 3.21 CPU) @ 2906.85/s (n=9331)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: strange rounding behaviour
by tilly (Archbishop) on May 18, 2001 at 20:09 UTC | |
by lhoward (Vicar) on May 18, 2001 at 20:35 UTC |