in reply to Re: Filthy Floats
in thread Filthy Floats
Watchout, (s)printf does the rounding itself, it doesn't truncate!
but sadly this rounding is buggy on numbers ending in .5:printf "%.3f => %.2f\n", 1.023, 1.023; printf "%.3f => %.2f\n", 1.026, 1.026; #prints 1.023 => 1.02 1.026 => 1.03
A quick and ugly 'fix' is something like printf "%.5f => %.2f\n", 1.025+1e-10, 1.025+1e-10; For better solutions and some discussion see this recent thread.printf "%.5f => %.2f\n", 1.025, 1.025; # prints instead of the correct 1.03 1.025 => 1.02
-- Hofmator
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Filthy Floats
by scain (Curate) on Jul 16, 2001 at 21:14 UTC | |
|
Re: Re: Re: Filthy Floats
by I0 (Priest) on Jul 17, 2001 at 10:56 UTC | |
by Hofmator (Curate) on Jul 17, 2001 at 14:13 UTC | |
by iakobski (Pilgrim) on Jul 17, 2001 at 15:34 UTC | |
by I0 (Priest) on Jul 17, 2001 at 22:16 UTC |