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. Quote Link to comment 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 Quote Link to comment 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() Quote Link to comment 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] Quote Link to comment 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. 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.