I have a strange problem. In my db table I have a field called "shipping". It obviously holds a dollar amount.
I am looping through my products and calculating the shipping charges. This is where it gets interesting.
In the db I have an amount like 1.30, when I loop through the query and calculate (shipping * quantity) it screws the amount up.
Shipping = 1.30
Quantity = 2
2 x 1.30 is giving me 2.59999990463
Whatever happened to 2.60?
A strange db calculation error
1 reply to this topic
Posted 22 March 2006 - 12:28 PM
Floating point arithmetic is always screwy on computers because converting a decimal to binary cleanly isn't possible. Just make sure you always round things to the precision you need. In MySQL ROUND(2.599999, 2) = 2.60
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users