Home > Article > Backend Development > PHP: Keep one decimal place and not round_PHP Tutorial
$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."
";
?>