in reply to Printf/Sprintf Behavior Change
Here's a suggestion towards what to do about it.
Examples:
#!/usr/bin/perl -w use strict; my $floatNumber = 0.345; my $roundToTwoDecimals = int($floatNumber * 100) / 100; printf "\$roundToTwoDecimals = %0.02f\n", $roundToTwoDecimals; my $forcedRounding = int(($floatNumber + 0.005) * 100) / 100; printf " \$forcedRounding = %0.02f\n", $forcedRounding; exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-09-16@1955-Rounding>rounding.pl $roundToTwoDecimals = 0.34 $forcedRounding = 0.35
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Printf/Sprintf Behavior Change (stupid printf)
by tye (Sage) on Sep 16, 2013 at 19:20 UTC | |
by marinersk (Priest) on Sep 17, 2013 at 09:25 UTC | |
|
Re^2: Printf/Sprintf Behavior Change
by McA (Priest) on Sep 16, 2013 at 18:36 UTC | |
by marinersk (Priest) on Sep 17, 2013 at 09:51 UTC |