Might look excessive but will convert any given format no mater the locale:
function normalizeDecimal($val, int $precision = 4): string
{
$input = str_replace(' ', '', $val);
$number = str_replace(',', '.', $input);
if (strpos($number, '.')) {
$groups = explode('.', str_replace(',', '.', $number));
$lastGroup = array_pop($groups);
$number = implode('', $groups) . '.' . $lastGroup;
}
return bcadd($number, 0, $precision);
}
Output:
.12 -> 0.1200
123 -> 123.0000
123.91 -> 12345678.9100
123 456 78.91 -> 12345678.9100
123,456,78.91 -> 12345678.9100
123.456.78,91 -> 12345678.9100
123 456 78,91 -> 12345678.9100