<?php
echo 'Comma Formatted: ' . nyx_number_format('1.233.332,34', 'comma');
echo 'Dot Formatted: ' . nyx_number_format('1,233,332.34', 'dot');
function nyx_number_format($number, $separator = 'dot') {
// Default setting
$thousand_separator = ',';
$decimal_separator = '.';
if ($separator == 'comma') {
$thousand_separator = '.';
$decimal_separator = ',';
}
// Remove the thousand separator
$number = str_replace($thousand_separator, '', $number);
// Make sure the Decimal separator is correct
$number = str_replace($decimal_separator, '.', $number);
if ($separator == 'comma') {
return number_format($number, 2, ',', '.');
}
return number_format($number, 2, '.', ',');
}
preferences:
45.89 ms | 402 KiB | 5 Q