in reply to Re: int's behaviour
in thread int's behaviour
That's a good suggestion, but beware that sprintf uses the round-to-even method of rounding.
$ perl -e 'printf "%.0f\n", 2.5;' 2 $ perl -e 'printf "%.0f\n", 1.5;' 2
To get the usual "round up" method, I usually use int with the value plus a half.
$ perl -le '$x=1.5;print int($x+.5)'; 2 $ perl -le '$x=2.5;print int($x+.5)'; 3
|
|---|