dodgyJim Posted March 22, 2006 Share Posted March 22, 2006 Hiya,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.30Quantity = 22 x 1.30 is giving me 2.59999990463Whatever happened to 2.60?Any ideas?cheers. Link to comment https://forums.phpfreaks.com/topic/5481-a-strange-db-calculation-error/ Share on other sites More sharing options...
wickning1 Posted March 22, 2006 Share Posted March 22, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5481-a-strange-db-calculation-error/#findComment-19622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.