Yeah, I see, working on a new one.
Okay, try the below, both with and without the following commented:
Code:
// $locale_info['decimal_point'] = ',';
Depending on your $locale_info['decimal_point'] it should work one way but not the other.
Code:
<?php
$variables = array(
'1999',
'1999.49',
'1999,49',
'1,999.49',
'1.999,49',
'1,999.5'
);
$locale_info = localeconv();
foreach ($variables AS $variable)
{
// $locale_info['decimal_point'] = ',';
$variable_orig = $variable;
if ($locale_info['decimal_point'] == ',')
{
$variable = str_replace(array('.',','), array('','.'), $variable);
}
else
{
$variable = str_replace(',', '', $variable);
}
$variable = sprintf("%01.2f", $variable);
echo $variable_orig.' => '.$variable."\n<br />\n";
}
?>
With $locale_info['decimal_point'] commented (my decimal point is period):
Code:
1999 => 1999.00
1999.49 => 1999.49
1999,49 => 199949.00 XX
1,999.49 => 1999.49
1.999,49 => 2.00 XX
1,999.5 => 1999.50
With $locale_info['decimal_point'] UNcommented (my decimal point now comma):
Code:
1999 => 1999.00
1999.49 => 199949.00 XX
1999,49 => 1999.49
1,999.49 => 2.00 XX
1.999,49 => 1999.49
1,999.5 => 2.00 XX
So it depends on the $locale_info['decimal_point'] setting.