The content of this section:
PHP retains several digits after the decimal point
Example:
<?php$n = "10.6789";//One, retain 2 decimal points and round//Use round () method Echo round ($n, 2); echo "<br>";//Use Number_format () method Echo Number_format ($n, 2); echo "<br>"//Use sprintf () method Echo sprintf ("%.2f", $n); echo "<br>";
Second, retain 2 decimal places, but do not round
Echo ((int) ($n *100))/100;
Attached, PHP takes a few decimal points after the function number_format a simple example.
String Number_format (float number [, int decimals [, String Dec_point, String thousands_sep])
Code:
< $short _pi = "3.14159", $my _pi = Number_format ($short _pi, 2); Echo $my _pi. " \ n "; 3.14$foo = 850017.9021; Www.jbxue.com$new_foo = Number_format ($foo, 3, ".", ""), Echo $new _foo. " \ n "; 850 017.902?>
Description
The Number_format function is used to format the number of numbers.
The second function, decimals, is used to keep the numbers behind several.