php如何保留一位小数,包括0,内详?
来源:百度知道 编辑:UC知道 时间:2024/05/24 14:36:00
例如一个数字在数据库中为60 ,用php显示出来显示为60.0
怎么实现?
不用四舍五入
怎么实现?
不用四舍五入
PHP变量保留一位小数,包括0;可以考虑使用sprintf函数,控制浮点数格式。示例如下:
<?php
header("Content-type:text/html;charset=utf-8;");
$money=20;
$money=sprintf("%.1f",$money);
echo $money;
//20.0
$money2=20.20;
$money2=sprintf("%.1f",$money2);
echo $money2;
//20.2
number_format(变量,保留位数)
$number=number_format($number, 1);
对不起,莫不会拍黄片