DarkPrince2005 Posted April 26, 2011 Share Posted April 26, 2011 Is there an easy way for me to return 123.50 instead of 123.5.... I'm trying to return the trailing zero? Link to comment https://forums.phpfreaks.com/topic/234740-currency-format/ Share on other sites More sharing options...
saurabhx Posted April 26, 2011 Share Posted April 26, 2011 Not clean, but this works:- <?php $number = '123.5...'; sscanf($number, '%d.%d%s', $a, $b, $s); $len = strlen($s)-1; while ($len >= 0) { if ($s[$len] == '.') { $s[$len] = '0'; $s[$len+1] = ''; } $len--; } echo trim($a.'.'.$b.$s); // Will output 123.50 ?> Link to comment https://forums.phpfreaks.com/topic/234740-currency-format/#findComment-1206319 Share on other sites More sharing options...
silkfire Posted April 26, 2011 Share Posted April 26, 2011 saur I think those 3 dots were just an ellipsis. sure do: $number = number_format(123.5, 2); Link to comment https://forums.phpfreaks.com/topic/234740-currency-format/#findComment-1206339 Share on other sites More sharing options...
saurabhx Posted April 26, 2011 Share Posted April 26, 2011 @silkfire oops, my bad Link to comment https://forums.phpfreaks.com/topic/234740-currency-format/#findComment-1206348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.