javascript float arithmetic
well, I've a javascript code which uses two arrays:
items [id,name, price]
prices are float from mysql db.representation of an order in html form which i iterate us开发者_开发技巧ing jquery
now I compute the total price
I run over the second table and retrieves proper price from the first. but I get the answer+0.000000001. which i use tofixed to cut. but still I'm puzzled if this is a known behavior.yes. it's known behavior, and the good example
0.1 + 0.2 = 0.30000000000000004
Could you update your DB query to multiply the price by 100 and so return it in (whatever your smallest unit of current is... pence, cents, etc)? That way you're dealing with integers and can just format your output when you want to display it.
精彩评论