Home >Backend Development >PHP Tutorial >Differences in usage of php rounding functions ceil, floor, round, intval
2. floor — rounding by rounding illustrate float floor ( float $value ) Returns the next integer not greater than value, with the decimal part of value rounded off. The type returned by floor() is still float because the range of float values is usually larger than that of integer. floor() example
3, round — perform floating point numbers rounding illustrate float round ( float $val [, int $precision ] ) Returns val rounded to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (default). round() example
Note: PHP cannot handle strings like "12,300.2" correctly by default. Note: The precision parameter was introduced in PHP 4. 4. intval — Get the integer value of the variable illustrate int intval ( mixed $var [, int $base ] ) Returns the integer value of variable var using a specific base conversion (default is decimal). var can be any scalar type. intval() cannot be used with arrays or objects. intval() example
Instructions: The base argument to intval() has no effect unless the var argument is a string. Summary: The floor function has the same function as the intval function. The difference is that one returns a floating point number (float) and the other is an integer (integer), because the range of float values is usually larger than that of integer. But as far as the numerical value itself is concerned Both are equal. |