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
https://forums.phpfreaks.com/topic/130326-datatype-for-storing-money-in-mysql/
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

  • 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

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.