PHP format MySQL return float type method, Phpmysql return float
The example in this article describes how PHP formats MySQL to return a float type. Share to everyone for your reference, as follows:
PHP Gets the float field of MySQL, after the echo output, the decimal part contains more than 0.
You can use Floatval ($num) to leave 0.
To retain the decimal place, use Number_format ($num, 2);
The Number_format function rounds a value that exceeds the specified number of digits.
If you do not want to round, keep all decimals. You can use the following methods:
If you want to keep only two decimal places available Number_format ($num, 2); Echo f (' 1001.334534 ', 2). '
'; 1001.334534echo f ('-1001.000 ', 2). '
'; -1001.00echo f (' 1001.3 ', 5). '
'; 1001.30000echo f (' 1001.33 '). '
'; 1001.33echo f (' 1001.000 '). '
'; 1001//formatting decimals, but not rounding, if there are decimals are all reserved, no decimals add 0;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;}
More interested in PHP related content readers can view this site: "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL Database Operations Primer, and PHP Common database operations Tips Summary
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- Php+mysql How the date time is converted (Unix timestamp and formatted date)
- PHP Gets the current date and time and formatting method parameters
- PHP Format Phone number method
- PHP implementation format Multiple lines of text to JS available format
- PHP Date function method of formatting Unix time
- PHP Formatted amount function sharing
- Summary of commonly used string formatting functions in PHP
- PHP File size Format Function collection
- PHP format Date and time format sample sharing
http://www.bkjia.com/PHPjc/1117059.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117059.html techarticle php format MySQL return float type method, Phpmysql return Float This example describes the PHP format MySQL return float type method. Share to everyone for your reference, as follows: ...