>  기사  >  백엔드 개발  >  PHP:保留小数点后一位,并且不四舍五入_PHP教程

PHP:保留小数点后一位,并且不四舍五入_PHP教程

WBOY
WBOY원래의
2016-07-13 10:42:251435검색


$total = 1225.49.5;

$total = floor( ($total*0.95)* 10 ) /10;

$total = sprintf('%.1f', (float)$total);

echo $total;


?>

输出结果:1225.4


php保留小数点后一位的几种方法


$total = number_format(2/3,1); // 1表示保留的是小数点后一位,会四舍五入
echo $total ."
";


$total_1 =sprintf( "%.1f ",2/3); // 1f表示小数点后一位
echo $total_1 ."
";


$total_2=printf( "%.1f ",2/3);
echo $total_2."
";


?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/635056.htmlTechArticle$total = 1225.49.5; $total = floor( ($total*0.95)* 10 ) /10; $total = sprintf('%.1f', (float)$total); echo $total; ?> 输出结果:1225.4 php保留小数点后一位的几种方法...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.