PHP format the float type returned by MYSQL, and phpmysql returns float. PHP: format MYSQL to return the float type. phpmysql returns the float type. this example describes how to format MYSQL to return the float type. For your reference, the details are as follows: PHP formatting MYSQL returns the float type, and phpmysql returns the float type.
This example describes how to format the float type returned by MYSQL in PHP. We will share this with you for your reference. The details are as follows:
PHP obtains the mysql float field. after echo is output, the fractional part contains multiple 0.
You can use floatval ($ num) to remove 0.
To retain decimal places, use number_format ($ num, 2 );
The number_format function rounds the value that exceeds the specified number of digits.
If you do not want to rounding, keep all decimals. You can use the following methods:
// If you only want to retain two decimal places, you can use number_format ($ num, 2); echo f ('192. 100', 2 ).'
'; // 1001.334534 echo f ('-1001.000 ', 2 ).'
'; //-1001.00 echo f ('192. 3', 5 ).'
'; // 1001.30000 echo f ('192. 33 ').'
'; // 1001.33 echo f ('2014. 000 ').'
'; // 1001 // format the decimal point, but it is not rounded in. if there is a decimal point, it is retained. if there is no decimal point, 0 is added. function f ($ num, $ v = 0) {$ num = floatval ($ num); if ($ v> 0) {$ num = ''. $ num; $ arr = explode ('. ', $ num); if (count ($ arr) = 1) {$ num. = '. '. str_repeat ('0', $ v);} else {$ v-= strlen ($ arr [1]); if ($ v> 0) $ num. = str_repeat ('0', $ v) ;}return $ num ;}