I have this number 1003636 and i need to convert in this format 1.003,636 how to convert with php, this is a dynamically numbers from rows of mysql.
2 Answers
You need to use number_format(), but there's no way of telling the function that the last 3 numbers are the decimals. So you need to first divide by 1000, and then use the function:
<?php $n = 1003636; $n /= 1000; echo number_format($n, 3, ",", "."); // 1.003,636 - 3 decimals, separate thousands by . and decimals by , Comments
PHP has a build in function, number_format. http://php.net/manual/en/function.number-format.php
E.G.
$number = 1003636; echo number_format($number); // This would output 1,003,636 Worth checking out the documentation, as their are certain parameters you can pass for dealing with foreign numbers, e.g. dots instead of commas and vice verse.