How to keep one decimal place in PHP without rounding

coldplay.xixi
Release: 2023-03-04 20:48:02
Original
3675 people have browsed it

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)].

How to keep one decimal place in PHP without rounding

[Related learning recommendations:php programming(video)]

PHP retains decimal points The last digit and not rounded method:

Commonly used methods are as follows:

Copy after login

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."
"; ?>
Copy after login

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!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!