rcouser Posted September 22, 2008 Share Posted September 22, 2008 Hello, What is the best way to store price in MySQL? Say for example I can be sure the that the price is a whole number and therefore use INT, how do I use php to change how the number is displayed on screen to the user. For example: 47500 is store in database but £47,500.00 is what the user sees. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/125334-best-way-to-store-price-in-mysql/ Share on other sites More sharing options...
FVxSF Posted September 22, 2008 Share Posted September 22, 2008 You could save as an INT then once you pull it from the database you can use the php number_format() function. Link to comment https://forums.phpfreaks.com/topic/125334-best-way-to-store-price-in-mysql/#findComment-647823 Share on other sites More sharing options...
rcouser Posted September 22, 2008 Author Share Posted September 22, 2008 Hi FVxSF, Just googled number_format() and it seems to do the trick Cheers Link to comment https://forums.phpfreaks.com/topic/125334-best-way-to-store-price-in-mysql/#findComment-647825 Share on other sites More sharing options...
Mchl Posted September 22, 2008 Share Posted September 22, 2008 There's also money_format() in case you need it. And if you ever need to store a price with decimals, don't store it as a FLOAT column. Use DECIMAL instead. Link to comment https://forums.phpfreaks.com/topic/125334-best-way-to-store-price-in-mysql/#findComment-647872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.