This article mainly introduces the PHP division operations rounded rounding, up rounding, down rounding, the use of fractional interception, has a certain reference value, now share to everyone, there is a need for friends can refer to
PHP takes integer functions commonly used in four ways:
1. Direct rounding, discarding decimals, preserving integers: intval ();
2 Rounding and Rounding: round ();
3. Rounding up, there are decimals on the addition of 1:ceil ();
4. Rounding Down: Floor ().
First, intval-the variable into an integer form
Intval If the character type is automatically converted to 0, it is usually used to cast a numeric type, but it is important to note that it is recommended to use (int) if the length is too long.
Intval (5.2); 5intval (5.6); 5intval (' abc '); 0
Second, rounding: round ()
The parameter 1 is rounded according to the specified precision of parameter 2. The parameter 2 can be a negative number or 0 (the default).
Round (5.2); 5round (5.8); 6round (5.88888, 0); 6round (5.83333, 2); 5.83round (5.83353, 3); 5.834round (5201314,-2); 5201300
Three, upward rounding, there are decimals on the addition of 1:ceil ()
Echo (Ceil (0.60); 1echo (Ceil (0.40); 1echo (Ceil (5); 5echo (Ceil (5.1); 6echo (Ceil ( -5.1); -5echo (Ceil ( -5.9)); -5
Four, downward rounding: Floor ()
echo (Floor (0.60)); 0echo (Floor (0.40)); 0echo (Floor (5)); 5echo (Floor (5.1)); 5echo (Floor (-5.1)); -6echo (Floor ( -5.9))//-6