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
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.

Link to comment
Share on other sites

@ 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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.