[thelist] Numbers Just Don't Add Up
Sarah Adams
mr.sanders at geekjock.ca
Thu Jan 18 07:32:14 CST 2007
> I was able to fix my problem with:
>
> invoiceTotal = eval(invoiceSubtotal) + eval(invoiceShipping) +
> eval(invoiceCOD)
You should try to avoid using the eval() function unless it absolutely
can't be helped. I'd go with Lee's suggestion of casting to ensure that
your variables get treated as numbers. Or if you want something dead
simple (but slightly hackish), try something like this:
invoiceTotal = 1* invoiceSubtotal + invoiceShipping + invoiceCOD
The "1*" tells javascript that you're working with numbers, not
concatenating strings.
--
sarah adams
web developer & programmer
portfolio: http://sarah.designshift.com
blog: http://hardedge.ca
More information about the thelist
mailing list