[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Sales Tax Calculation
On Wed, 15 Sep 1999 mikeh@minivend.com wrote:
> ****** message to minivend-users from mikeh@minivend.com ******
>
> Quoting John Vozza (john@netrom.com):
> >
> > Ryan
> >
> > Further testing showed that any sales amount that ended with .25 or .75
> > always generated tax that was off by 1 cent. (Using a tax rate of 6%,
> > entered in salestax.asc as .06 or .060 made no difference.)
> >
> > The error seems to stem from the sprintf used in calculating the tax. I
> > guess Perl is not "rounding" properly.
> >
>
> Operating system? C library in use? Perl uses the standard C libraries
> on your system, and glibc seems to get it right.
>
> This little script:
>
> @tries = (.02, .024, .025, .026);
>
> for(@tries) {
> print sprintf "round $_ to 2 places: %.2f\n", $_;
> }
>
> Yields this on Linux/glibc:
>
> round 0.02 to 2 places: 0.02
> round 0.024 to 2 places: 0.02
> round 0.025 to 2 places: 0.03
> round 0.026 to 2 places: 0.03
>
Mike
Your script generates the same, correct results on my Linux 2.0.36/libc
Perl 5.004_4 system.
However, a slight mod to your script which is more inline with minivend's
code generates the error.
@tries = (25.24, 25.25, 25.26);
for(@tries) {
$r = $_ * .06;
print sprintf "round $r to 2 places: %.2f\n", $r;
}
round 1.5144 to 2 places: 1.51
round 1.515 to 2 places: 1.51
round 1.5156 to 2 places: 1.52
Do you think this is a libc vs glibc issue? (Could you try on your system)
My libc=/lib/libc.so.5.4.44
Thanks
John
-------------------------------------------------------------------------
NetRom Internet Services 973-208-1339 voice
john@netrom.com 973-208-0942 fax
http://www.netrom.com
-------------------------------------------------------------------------