PHP保留小数三种方法

https://www.jb51.net/article/166138.htm

number_format(number,decimals,decimalpoint,separator)  //如果是0会进行保留 即10.40 会变成10.40
第一个为数字第二个为保留位数第三位为小数点的形式第四位是千分位的形式

round($num,2); //10.46  如果是0不会保留 级10.40会变成10.4

$format_num = sprintf("%.2f",$num);//同number_format  即10.40 会变成10.40
<?php
echo number_format("1000000",2,".","");
echo number_format("1000000",2,".","x");
echo number_format("1000000",2,"y","x");
?>

1000000.00
1x000x000.00
1x000x000y00
发布了658 篇原创文章 · 获赞 73 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/fujian9544/article/details/103971314
今日推荐