PHP uses the Number_format function to intercept the decimal method analysis, Number_format decimal
This example describes how PHP uses the Number_format function to intercept decimals. Share to everyone for your reference, as follows:
You know that using PHP's Number_format () function, you can group numbers by thousands. But it will round up the numbers, is there any way that it can simply discard the decimals behind the reserved bits without rounding them? Everybody don't worry, and listen to me carefully, if you want to keep two decimal places, you can put your number -0.005
For example:
123456.6588
The result you want is:
123,456.65
You can do this:
$num =123456.6588;echo Number_format ($num -0.005,2, ".", ",");
If you only want to keep integers, you can
$num =123456.6588;number_format ($num-0.5);
The problem is done!
Add: small make up here to recommend a site of the PHP format beautification of the layout tools to help you in the future of PHP programming code layout:
PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat
In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format:
C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json
More interested in PHP related content readers can view the site: "PHP Math Skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, " PHP Sorting algorithm Summary, "PHP Common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string Usage Summary" and " A summary of common PHP database operation techniques
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1133064.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133064.html techarticle PHP uses Number_format function to intercept decimal method analysis, Number_format fractional This article describes the PHP method of using Number_format function to intercept decimals. Share to everyone for your reference, ...