Java Adding error
Hey, my first post, I was sent here by a friend, This is the problem i have been haveing with my code my our web site
I have been "learning" how to become the web developer under a complete moron at my school. and we recently came across this problem. This site is supposta add up the quanity * the price for the total then add the totals up for the grand total at the bottom. And it dose this great in java....unlesss you use certain prices with numbers like 2,4,8,16,32,64,128 and so on as the quanities. i did 2 quanties of an item costign 40.29 and then 2 of an item cost 60.47. and the grand total always comes out 1 cent short!!! WTF!!! anone who can help here is the source
[690 byte] By [
CoNMaN] at [2007-11-18 5:56:20]

# 1 Re: Java Adding error
it would be useful if you included the code that preformed that opperation in a post.
but if you are adding then multiplying, make sure you use order of operations (PEMDAS) so (add + add) * mult
maybe that will help
# 2 Re: Java Adding error
I briefly looked at your code. This is done in Javascript, no? You saying Java threw me for a sec. That being said, I would bet good money your problme lies with the fact that you are doing calculations using floating values. Decimal values stored in binary (as the computer does) sometimes get rounding errors. Try converting all your dollar amounts to cents (multiply times 100), do your calculations and turn back into dollars (divide by 100). This will likely cure your problem.
Nemi at 2007-11-8 0:15:00 >

# 3 Re: Java Adding error
i did Nemi and it solved it, thanks a ton!