182x Posted November 17, 2006 Share Posted November 17, 2006 Hey guys, In my datbase I have a field called amount which is a float so if I enter 12.24 thats fine but if I add .06 ot that it will be entered in the database and displayed as 12.3 rather than 12.30 is there a way to change this?Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/27597-format-number-question/ Share on other sites More sharing options...
Psycho Posted November 17, 2006 Share Posted November 17, 2006 In the database? I don't think so. What does it matter how it is stored in the database. Just use number_format() to format the number appropriately when echoing it to the page.http://us3.php.net/manual/en/function.number-format.php Link to comment https://forums.phpfreaks.com/topic/27597-format-number-question/#findComment-126211 Share on other sites More sharing options...
esukf Posted November 17, 2006 Share Posted November 17, 2006 If you're using mysql, you can change the data type of the column in the database to decimal(M,D) where M is the total number of digits and D the number of digits after the decimal point.As mjdamato said you can just format the number after it's been pulled from the database using number_format() Link to comment https://forums.phpfreaks.com/topic/27597-format-number-question/#findComment-126214 Share on other sites More sharing options...
182x Posted November 17, 2006 Author Share Posted November 17, 2006 Nice one thanks guys for the syntax of number_format() when dealing with session variables I have to leave off the quotes is the following correct:[code]echo number_format($HTTP_SESSION_VARS['curr'],2)[/code]or should it be:[code]echo number_format("$HTTP_SESSION_VARS['curr']",2)[/code] Link to comment https://forums.phpfreaks.com/topic/27597-format-number-question/#findComment-126228 Share on other sites More sharing options...
Orio Posted November 17, 2006 Share Posted November 17, 2006 [code]echo number_format($HTTP_SESSION_VARS['curr'],2);[/code]is the right version.Orio. Link to comment https://forums.phpfreaks.com/topic/27597-format-number-question/#findComment-126234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.