php怎么将int(整数)类型转为小数
- 建站笔记
- 2022-05-15
- 505
转换方法:1、使用number_format()函数,语法“number_format(int类型的数值,小数位数)”;2、使用sprintf()函数,语法“sprintf("%.xf",int类型的值)”,参数x为小数位数。
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php将int(整数)类型转为小数
方法1:使用number_format()函数
number_format()可通过千位分组来格式化数字。
<?php echo number_format(12,1)."<br>"; echo number_format(12,2)."<br>"; echo number_format(12,3)."<br>"; echo number_format(12,4)."<br>"; ?>
方法2:使用sprintf()函数
sprintf() 函数把格式化的字符串写入一个变量中。
<?php echo sprintf("%.1f",12)."<br>"; echo sprintf("%.2f",13)."<br>"; echo sprintf("%.3f",14)."<br>"; echo sprintf("%.4f",15)."<br>"; ?>
本文由白琉璃于2022-05-15发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/2490.html
发表评论