PHP method of retaining one decimal point and not rounding: 1. Use the function [number_format], the code is [$total=number_format(2/3,1)]; 2. Use the function [$total_1 =sprintf( "%.1f ",2/3)].
[Related learning recommendations:php programming(video)]
PHP retains decimal points The last digit and not rounded method:
Commonly used methods are as follows:
Output result: 1225.4
php retains the decimal point Several methods for one person
"; 方法:$total_1 =sprintf( "%.1f ",2/3); // 1f表示小数点后一位 echo $total_1 ."
"; $total_2=printf( "%.1f ",2/3); echo $total_2."
"; ?>
Related learning recommendations:Programming video
The above is the detailed content of How to keep one decimal place in PHP without rounding. For more information, please follow other related articles on the PHP Chinese website!