irkevin Posted October 29, 2009 Share Posted October 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted October 29, 2009 Share Posted October 29, 2009 Decimal should work just fine. You probably heard float was bad because it has WAY more precision than necessary for currency, but it certainly would work too. Can you post your INSERT query? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2009 Share Posted October 29, 2009 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. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted October 29, 2009 Share Posted October 29, 2009 you need to set it to DECIMAL(15,2). if you just set it to DECIMAL(), it treats it as 0,0, which will offset everything, and have no number to the right of the decimal. Think of it like this: DECIMAL(THE_LEFT,THE_RIGHT) Quote Link to comment Share on other sites More sharing options...
irkevin Posted October 29, 2009 Author Share Posted October 29, 2009 @ 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.