PHP: keep the last decimal point and keep the last decimal place rounded. $ Total1225.49.5; $ totalfloor ($ total * 0.95) * 10) 10; $ totalsprintf (%. 1f, (float) $ total); echo $ total ;? Output: 1225.4php: several methods to retain the last decimal point
$ Total = 1225.49.5;
$ Total = floor ($ total * 0.95) * 10)/10;
$ Total = sprintf ('%. 1f', (float) $ total );
Echo $ total;
?>
Output result: 1225.4
Several methods for retaining the last decimal point in php
$ Total = number_format (2/3, 1); // 1 indicates that the last digit of the decimal point is retained and is rounded
Echo $ total ."
";
$ Total_1 = sprintf ("%. 1f", 2/3); // 1f indicates the last decimal point
Echo $ total_1 ."
";
$ Total_2 = printf ("%. 1f", 2/3 );
Echo $ total_2 ."
";
?>
Cost = 1225.49.5; $ total = floor ($ total * 0.95) * 10)/10; $ total = sprintf ('%. 1f', (float) $ total); echo $ total;?> Output result: 1225.4 php retains the first digit after the decimal point...