function ToMoney($string)
{
$Negative = 0;
if(preg_match('/^-/',$string))
{
$Negative = 1;
$string = preg_replace('|-|','',$string);
}
$string = preg_replace('|,|','',$string);
$Full = split('[.]',$string);
$Count = count($Full);
if($Count > 1)
{
$First = $Full[0];
$Second = $Full[1];
$NumCents = strlen($Second);
if($NumCents == 2)
{
//do nothing already at correct length
}
else if($NumCents < 2)
{
$Second = $Second . '0';
}
else if($NumCents > 2)
{
$Temp = substr($Second,0,3);
$Rounded = round($Temp,-1);
$Second = substr($Rounded,0,2);
}
}
else
{
$First = $Full[0];
$Second = '00';
}
$length = strlen($First);
if( $length <= 3 )
{
$string = $First . ',' . $Second;
if($Negative == 1)
{
$string = '-' . $string;
}
return $string;
}
else
{
$loop_count = intval(( $length / 3 ));
$section_length = -3;
for($i = 0; $i < $loop_count; $i++)
{
$sections[$i] = substr($First, $section_length, 3);
$section_length = $section_length - 3;
}
$stub = ($length % 3);
if($stub != 0)
{
$sections[$i] = substr($First, 0, $stub);
}
$Done = implode(',', array_reverse($sections));
$Done = $Done . ',' . $Second;
if($Negative == 1)
{
$Done = '-' . $Done;
}
return $Done;
}
}
La Chaise sauvage a dit:
➡️ Offre MyRankingMetrics ⬅️
pré-audit SEO gratuit avec RM Tech (+ avis d'expert)
coaching offert aux clients (avec Olivier Duffez ou Fabien Faceries)
Voir les détails ici