Get the App
SLTechnology News&Howtos  ›  Development  › 

How php displays only 3 decimal places

Shulou Source: shulou.com Published: 2022-06-02 14:35:14 09月21日 Update

This article mainly introduces how php displays only 3 decimal places, which is very detailed and has certain reference value. Friends who are interested must finish reading it!

In PHP, you can use the number_format () function to display 3 decimal places, which can format numbers by grouping numbers in thousands of places, and can set the number of decimal places that return the result, with the syntax "number_format (numeric object to be formatted, 3);".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The method of displaying only 3 decimal places in php

1. Create a new php file, named test.php, to explain how php sets the number of decimal places. 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 to 3 decimal places, and the result is saved in the $res variable. Output the result of decimal processing through echo.

Open the test.php file in a browser and view the results.

Summary:

1. Create a decimal variable for testing.

2. Use the number_format function to keep the number to 3 decimal places, and the result is saved in the $res variable.

3. Output the result of decimal processing through echo.

The above is all the contents of the article "how to display only 3 decimal places in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Decimals results functions variables numbers files formats digits contents methods articles processing testing output value interests objects boys buddies decimal points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi NVidia Docker Redmi