问题
Probably a simple problem if you know the answer.
What I have
Numbers with no spaces.
$str = 10000;
$str2 = 100000;
What I want
Convert above to below...
$str = '10 000';
$str2 = '100 000';
Own thoughts
I thought of some strpos, regexp, str_replace but is it really the way to solve this? I will accept the most correct, short code answer with no lack of speed.
回答1:
Use number_format function. With space
for thoudsandsSparator as below.
number_format($number, 0, '.', ' ')
Codepad Demo.
回答2:
Look no further than number_format.
回答3:
use number_format:
$formatted = number_format(
$number, $numberOfDecimals, $decimalSeperator, $thousandsSeperator);
来源:https://stackoverflow.com/questions/15677094/php-correct-way-to-add-space-between-numbers