Jump to content

Currency losing decimals when value = 0 inserting into DB


Rottingham

Recommended Posts

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?

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?

Archived

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

×
×
  • Create New...

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.