Rottingham Posted August 5, 2008 Share Posted August 5, 2008 Hello, I am having problems inserting values into a database with a price not keeping decimal values if the number equals zero. I am using money_format() on my values to ensure that all values are given the proper decimals. THe table field is a FLOAT field. If I attempt to insert 21.90 stores as 21.9. If I attempt to insert 55.00 it saves 55 I can switch the field type to VarChar but I wanted float. I bet the solution is easy but, what am I missing? Link to comment https://forums.phpfreaks.com/topic/118201-currency-losing-decimals-when-value-0-inserting-into-db/ Share on other sites More sharing options...
JonnyThunder Posted August 5, 2008 Share Posted August 5, 2008 The DB is doing what it's meant to do. You need to format these numbers again when you grab them from your database, using sprintf() or something similar. Link to comment https://forums.phpfreaks.com/topic/118201-currency-losing-decimals-when-value-0-inserting-into-db/#findComment-608416 Share on other sites More sharing options...
abdfahim Posted August 5, 2008 Share Posted August 5, 2008 or using number_format(). Link to comment https://forums.phpfreaks.com/topic/118201-currency-losing-decimals-when-value-0-inserting-into-db/#findComment-608417 Share on other sites More sharing options...
Rottingham Posted August 5, 2008 Author Share Posted August 5, 2008 The DB is doing what it's meant to do. You need to format these numbers again when you grab them from your database, using sprintf() or something similar. Why would the database trim those zero values as 'part of it's job'? Is this a mechanism to shave off some bytes of data and processing? Link to comment https://forums.phpfreaks.com/topic/118201-currency-losing-decimals-when-value-0-inserting-into-db/#findComment-608578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.