Jump to content

Format number question


182x

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.