Hello everyone i am trying to format the input number range with php number_format
dot should be in multiplier of 3 digit and last two (if available in input range) digits should be come with comma separater
out put should be as per dutch format and dot should be in multiplier of 3 digit and last two digits should be come with comma separater
like, here is link you can put any input value from above list in textbox you can get output like shown below
the code which i am using
echo numberFormat('12345');
function numberFormat($num)
{
     return preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",".",$num);
}
but it will not work with (4),(5),(6) from my input probability to match with outputs.
Well I think is like this:
$number = 1234.56
echo number_format($number, 2, ',', '.');
About the input yo could check and all the "." remove it and the "," replace with "."
$number = "123.456,78";
$temp = str_replace(".", "", $number);
$temp2 = str_replace(",", ".", $temp);
echo number_format($temp2, 2, ',', '.');
I hope it helps
This is pretty similar to @Emesto solution, but forced into a number:
$num = '123.456.789,50';
$n = str_replace('.', '', $num);
$n = str_replace(',', '.', $n);
# $n is no longer a string
$n = $n + 0;
# so it should work fine in number_format
echo number_format($n,2,',','.');
PS: I just tested this code to be sure that it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With