Created
March 15, 2013 19:20
-
-
Save DWboutin/5172346 to your computer and use it in GitHub Desktop.
Espace des numéros dans l'argent PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatMoney($number, $fractional=false) { | |
if ($fractional) { | |
$number = sprintf('%.2f', $number); | |
} | |
while (true) { | |
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number); | |
if ($replaced != $number) { | |
$number = $replaced; | |
} else { | |
break; | |
} | |
} | |
return str_replace(',',' ',$number); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment