damien275x Posted May 26, 2012 Share Posted May 26, 2012 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 More sharing options...
Jessica Posted May 26, 2012 Share Posted May 26, 2012 divide by 100 and user number_format Link to comment https://forums.phpfreaks.com/topic/263165-php-convert-200-to-200-6050-to-6050-etc/#findComment-1348753 Share on other sites More sharing options...
thara Posted May 26, 2012 Share Posted May 26, 2012 use like this $n = 200/100 // ur value divide by 100 $n = number_format ($n, 2); // 2.00 Link to comment https://forums.phpfreaks.com/topic/263165-php-convert-200-to-200-6050-to-6050-etc/#findComment-1348775 Share on other sites More sharing options...
smoseley Posted May 26, 2012 Share Posted May 26, 2012 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 https://forums.phpfreaks.com/topic/263165-php-convert-200-to-200-6050-to-6050-etc/#findComment-1348779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.