Ste*_*Ste 5 php number-formatting
我有这个字符串:
000000000000100
Run Code Online (Sandbox Code Playgroud)
并需要将其转换为:
1,00
Run Code Online (Sandbox Code Playgroud)
所以,规则是:
Lek*_*eyn 18
string number_format(float $ number,int $ decimals = 0,string $ dec_point ='.',string $ thousands_sep =',')
如果您想要123456格式化的数字1234,45,请使用:
echo number_format($number / 100, 2, ",", "");
Run Code Online (Sandbox Code Playgroud)
如果你需要一个点作为千位分隔符(1.234,56):
echo number_format($number / 100, 2, ",", ".");
Run Code Online (Sandbox Code Playgroud)
将字符串转换为数字时,PHP会自动删除零.
string number_format ( float $number ,
int $decimals = 0 ,
string $dec_point = '.' ,
string $thousands_sep = ',' )
Run Code Online (Sandbox Code Playgroud)
手册:http://php.net/manual/en/function.number-format.php
// divide by 100 to shift ones place.
echo number_format((int)'000000000000100' / 100,2,',','');
Run Code Online (Sandbox Code Playgroud)