Home > Backend Development > PHP Tutorial > PHP: Keep one decimal place and not round_PHP Tutorial

PHP: Keep one decimal place and not round_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:42:25
Original
1552 people have browsed it


$total = 1225.49.5;

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

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

echo $total;


?>

Output result: 1225.4


Several ways to retain one decimal place in php


$total = number_format(2/3,1); // 1 means that one decimal place is retained and will be rounded
echo $total ."
";


$total_1 =sprintf( "%.1f ",2/3); // 1f represents one decimal place
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; ?> Output result: 1225.4 Several ways to retain one decimal place in php...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template