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
https://forums.phpfreaks.com/topic/263165-php-convert-200-to-200-6050-to-6050-etc/
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).

Archived

This topic is now archived and is closed to further replies.

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