Jump to content


This topic is now archived and is closed to further replies.


A strange db calculation error

Recommended Posts


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?

Any ideas?


Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.