The number_format() function formats a number with grouped thousands.
Example
<?php
echo number_format(" 1000000");
echo "<br />";
echo number_format(" 1000000",2);
echo "<br />";
echo number_format(" 1000000",2,",", ".");
?>

you can find more easy solution here
<url removed: no advertising...