[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Sales Tax Calculation
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
In a lot of cases, Minivend is only as good as the underlying
platform. The same is sometimes true for Perl, though not
as often. Neither are at fault in this case.
Perl tries very hard to find the right thing; try watching
the output of its Configure script some time...
--
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
131 Willow Lane, Floor 2 | || _ \
It's a little-known fact Oxford, OH 45056 | || |_) |
that the Y1K problem caused <mikeh@minivend.com> |___| _ <
the Dark Ages. -- unknown 513.523.7621 FAX 7501 |_| \_\