Home >Backend Development >PHP Tutorial >PHP rounding, rounding, rounding up, rounding down, decimal interception. What does rounding mean? Rounding is one hundred million. Excel value rounding

PHP rounding, rounding, rounding up, rounding down, decimal interception. What does rounding mean? Rounding is one hundred million. Excel value rounding

WBOY
WBOYOriginal
2016-07-29 08:49:025462browse

Four commonly used methods for PHP integer functions:

1. Round directly, discard decimals, and keep integers: intval();
2. Rounding: round();
3. Round up and add 1 if there are decimals: ceil();
4. Round down: floor().

1. intval—convert variables into integer types
If intval is a character type, it will be automatically converted to 0.

<code><span>intval(<span>3.14159</span>)</span>;  <span>// 3</span><span>intval(<span>3.64159</span>)</span>;  <span>// 3</span><span>intval(<span>'ruesin'</span>)</span>; <span>//0</span></code>

2. Rounding: round()

Rounds parameter 1 according to the precision specified by parameter 2. Parameter 2 can be negative or zero (default).

<code><span>round</span>(<span>3.14159</span>);      <span>// 3</span><span>round</span>(<span>3.64159</span>);      <span>// 4</span><span>round</span>(<span>3.64159</span>, <span>0</span>);   <span>// 4</span><span>round</span>(<span>3.64159</span>, <span>2</span>);   <span>// 3.64</span><span>round</span>(<span>5.64159</span>, <span>3</span>);   <span>// 3.642</span><span>round</span>(<span>364159</span>, -<span>2</span>);   <span>// 364200</span></code>

3. Round up and add 1 if there is a decimal: ceil()

Returns the next integer that is not less than value. If value has a decimal part, it will be rounded up by one.

This method is often used when we write paging classes to calculate the number of pages.

<code><span>ceil</span>(<span>3.14159</span>);  <span>// 4</span><span>ceil</span>(<span>3.64159</span>);  <span>// 4</span></code>

4. Round down: floor()

Returns the next integer not greater than value, and rounds the decimal part of value.

<code><span>floor</span>(<span>3.14159</span>);    <span>// 3</span><span>floor</span>(<span>3.64159</span>);    <span>// 3</span></code>

Please indicate the source for reprinting: http://blog.csdn.net/churk2012/article/details/51424588

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP rounding, rounding, rounding up, rounding down, and decimal interception, including rounding and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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