Jump to content

Currency format


DarkPrince2005

Recommended Posts

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

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.