Jump to content

Datatype for storing Money in MySQL


rcouser

Recommended Posts

I know this is a PHP forum but hope someone can help with storing money in MySQL.

I have been following a book to create a simple e-commerce and it uses float(10,2) but when I type in 565.50 it is stored at 565.00.

I have search page after page on google and seems to a big debate.

Hopefully someone has the answer.

Regards.

Link to comment
Share on other sites

Hey Canman2005,

Can you calculate totals if the amount is VARCHAR. Say in a shopping cart.

 

I believe so, I have never had any issues with using it, mostly because I have had to take existing large excel databases and don't want to chance messing up any money values, but then im not much of an expert and im sure other suggestions would be better, but personally I would stick with VARCHAR

Link to comment
Share on other sites

  • 1 month later...

Why you should not use float for money:

 

CREATE TABLE  `floatt` (
  `f` float DEFAULT NULL,
  `d` decimal(7,2) DEFAULT NULL
);

INSERT INTO `floatt` VALUES (0.33,0.33);

SELECT * FROM `floatt` WHERE f = 0.33;
0 rows returned

SELECT * FROM `floatt` WHERE f > 0.33;
1 row returned

SELECT * FROM `floatt` WHERE d = 0.33;
1 row returned

SELECT * FROM `floatt` WHERE d > 0.33;
0 rows returned

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.