Home > Article > Backend Development > How to display only 3 decimal places in php
In PHP, you can use the number_format() function to display 3 decimal places. This function can format numbers by thousands grouping. You can set the number of decimal places in the returned result. The syntax is "number_format(to format digital objects,3);".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php only displays 3 How to use decimal places
1. Create a new php file named test.php to explain how to set the number of decimal places in php. Use the header() method to set the encoding format of the page to utf-8. Create a decimal variable for testing.
2. In the test.php file, use the number_format function to keep the number with 3 decimal places, and the result is saved in the $res variable. Output the result after decimal processing through echo.
Open the test.php file in the browser to view the results.
Summary:
1. Create a decimal variable for testing.
2. Use the number_format function to keep the number with 3 decimal places, and the result is saved in the $res variable.
3. Output the result after decimal processing through echo.
If you are interested, you can click on "PHP Video Tutorial" to learn more about PHP knowledge.
The above is the detailed content of How to display only 3 decimal places in php. For more information, please follow other related articles on the PHP Chinese website!