RE: [PHP] Correct number format (curency)
| From: | Dennis Cole | Date: | Thu, 20 Feb 2003 20:08:12 +0000 |
| Subject: | RE: [PHP] Correct number format (curency) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136408@lists.php.net to get a copy of this message | ||
This should also work, without any problems.
----- Php Code ------
<?
$total = "1.000,00";
$total = str_replace(',','',$total);
echo number_format($total, 2, '.', '');
?>
----- End PHP Code ------
----- Original Message -----
From: Bas Jobsen [mailto:bas@startpunt.cc]
Sent: Thursday, February 20, 2003 10:05 AM
To: Robert Mena; php mailing list
Subject: Re: [PHP] Correct number format (curency)
> Example
>
> 1.000,00
> 1000.00
> 1,000.00
>
> I would like to convert those to a single format
> 1000.00
<?
function money(&$money)
{
/* written by bas@startpunt.cc */
$money=str_replace(array(',','.'),'',$money);
$money=substr($money,0,strlen($money)-2).'.'.substr($money,-2);
}
$money='1.000,00';
money($money);
echo $money."\n";
$money='1000.00';
money($money);
echo $money."\n";
$money='1,000.00';
money($money);
echo $money."\n";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php