perl / ifram / javascript question

Ian Petersen ispeters-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Wed Mar 14 14:17:52 UTC 2007


On 3/14/07, Madison Kelly <linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org> wrote:
> In this case the problem is Javascript is not very good at rounding.
> This is more of an issue because this is a financial program and a
> rounding error could cost me money or, worse, charge a customer too much
> money. Perhaps a penny here or there, but regardless, it would make me
> look unprofessional.

In the various sources I've seen that discuss this problem, the
solution is always to use an integer instead of a floating point, and
count pennies instead of dollars.

Unfortunately, Javascript doesn't have an integer type (the ECMA spec
defines Javascript numbers to be IEEE double-precision floating
points).  On the other hand, I think you can accurately represent at
least all the integers in a 32-bit int (roughly negative two billion
through positive two billion) in a double, so chances are your
financial calculations would all be accurate, even though you're using
a double.

Ian

-- 
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list