Jump to content

[SOLVED] php and mysql for storing money


irkevin

Recommended Posts

Hi

 

This is quite confusing me.. I've searched here but can't find an answer, please help

 

I have a table called products.. In which there is a price field. It's set to DECIMAL.

 

So, when i store money in it.. Say $44.50 , it cut off the .50 . Why is it so? How can I store the cents also?

 

I heard that using FLOATS isn't the good way to go, but then again, if DECIMAL doesn't display the cents, what should I do?

 

Any Advice guys or gals?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/179530-solved-php-and-mysql-for-storing-money/
Share on other sites

What is your exact column definition using DECIMAL and what is your code putting the values in and displaying the values and have you examined the data in the table directly using your favorite database management tool so you know what is actually stored so that you can pin down if the problem is putting the data in, if the DECIMAL usage is correct, or if the problem is in retrieving the data.

@ lemmin : I didn't write the query yet, I just fired up phpMyAdmin, and entered 44.50, but when saved, it become 45 :s :s

 

@PFMaBiSmAd  : I didn't write any code, but as you said, I entered it directly into the table, and came up with this problem.

 

Finally

 

@ jonsjava : setting it to DECIMAL(15,2) did the trick... Thanks a lot man XD

 

Thanks for your hepl everyone.. topic marked as solved I guess!

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.