Jump to content

PHP convert 200 to 2.00, 6050 to 60.50 etc


damien275x

Recommended Posts

I have a system that, as it is dealing with EFTPOS and is quite old, requires numbers in raw format, with no decimals

For example, 200 will be $2.00, 6050 is $60.50.

Now it returns the values with no decimal. What is the correct way I can manipulate variables to echo with the decimal places to the end user?

 

Thankyou in advance! :)

Link to comment
Share on other sites

To add to this...

 

round($val, 2) will round your number to 2 decimal places.

 

number_format($val, 2) will comma-delimit (or delimit per your locale) your number as well

 

money_format('%.2n', $val) will comma-delimit and add your currency symbol (per your locale)

 

setlocale(LC_MONETARY, 'en_US'); will set your monetary locale to US standards (globally).

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.