Home > Backend Development > PHP Tutorial > Analysis of how PHP uses the number_format function to intercept decimals, number_format decimal_PHP tutorial

Analysis of how PHP uses the number_format function to intercept decimals, number_format decimal_PHP tutorial

WBOY
Release: 2016-07-12 08:50:49
Original
1034 people have browsed it

Analysis of how PHP uses the number_format function to intercept decimals, number_format decimal

The example in this article describes how PHP uses the number_format function to intercept decimals. Share it with everyone for your reference, the details are as follows:

Everyone knows that you can use PHP's number_format() function to group numbers into thousands. But it will round the numbers. Is there any way to make it directly discard the decimals after the reserved digits without rounding? Don’t worry, please listen to me in detail. If you want to keep two decimal places, you can change your number to -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, ".", ",");

Copy after login

If you just want to keep integers you can

$num=123456.6588;
number_format($num-0.5);

Copy after login

Problem solved!

Supplement: The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:

php code online formatting and beautification tool:

http://tools.jb51.net/code/phpformat

In addition, since php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json

Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of PHP mathematical operation skills", "Summary of PHP operating office document skills (including word, excel, access, ppt)", "PHP array ( Array) operating skills collection", "php sorting algorithm summary", "php common traversal algorithms and techniques summary", "php data structure and algorithm tutorial", "php programming algorithm summary", "php regular expression usage summary", "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133064.htmlTechArticleAnalysis of how php uses the number_format function to intercept decimals, number_format decimal This article explains how php uses the number_format function to intercept decimals. . Sharing it with everyone for your reference,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template