PHP takes the integer function commonly four kinds of methods summary

  • 2020-05-17 05:03:14
  • OfStack

ceil -- round by 1
instructions
float ceil ( float value )
Returns the next integer not less than value, and value carries one if it has a decimal part. The type returned by ceil() is still float, because the range of float values is usually larger than that of integer.
Example 1. Example ceil()
 
<?php 
echo ceil(4.3); // 5 
echo ceil(9.999); // 10 
?> 

floor - rounding by elimination
instructions
float floor ( float value )
Returns the next integer not greater than value, rounding off the fractional portion of value. The type returned by floor() is still float, because the range of float values is usually larger than that of integer.
Example 1. Example floor()
 
<?php 
echo floor(4.3); // 4 
echo floor(9.999); // 9 
?> 

round - rounds 4 to 5 for floating point Numbers
instructions
float round ( float val [, int precision] )
Returns the result of rounding val by 4, 5, according to the specified precision, precision (number of digits to the decimal point of 10). precision can also be negative or zero (the default).
Example 1. Example round()
 
<?php 
echo round(3.4); // 3 
echo round(3.5); // 4 
echo round(3.6); // 4 
echo round(3.6, 0); // 4 
echo round(1.95583, 2); // 1.96 
echo round(1241757, -3); // 1242000 
echo round(5.045, 2); // 5.05 
echo round(5.055, 2); // 5.06 
?> 

intval - converts variables to integer type
Example intval ()
 
<?php 
echo intval(4.3); //4 
echo intval(4.6); // 4 
?> 

Related articles: