


PHP rounding function: introduction to the differences between ceil, floor, round and intval
The following is a detailed introduction to the differences between the rounding functions in PHP: ceil, floor, round, intval. Friends in need can come and refer to it
We often use PHP Rounding functions, mainly: ceil, floor, round, intval.
ceil -- further rounding
Explanation
float ceil (float value)
returns no The next integer less than value. If value has a decimal part, it is rounded up by one digit. The type returned by ceil() is still float because the range of float values is usually larger than that of integer.
PHP rounding function example 1. ceil() example
< ?php echo ceil(4.3); // 5 echo ceil(9.999); // 10 ?>
floor -- rounding by rounding
Explanation
float floor (float value)
Returns the next integer not greater than value, and rounds the decimal part of value. The type returned by floor() is still float because the range of float values is usually larger than that of integer.
PHP rounding function example 1. floor() example
< ? php echo floor(4.3); // 4 echo floor(9.999); // 9 ?>
round -- Round floating point numbers
Description
float round ( float val [, int precision] )
Returns the result of rounding val according to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (the default).
PHP rounding function example 1. round() example
< ? 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---convert the variable into an integer type
PHP rounding function example intval()
< ? php echo intval(4.3); //4 echo intval(4.6); //4 ?>
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to PHP Chinese website!
Related recommendations:
About the definition and usage of php htmlentities() function
About using openssl in PHP7.1 Introduction to replacing mcrypt
#
The above is the detailed content of PHP rounding function: introduction to the differences between ceil, floor, round and intval. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In PHP, round means "rounding" and is a built-in function that converts floating point numbers into integers. This function can round floating point numbers and return an integer value of type float. The syntax is "round(number, precision,mode);".

The round() function is a very useful function in the PHP number formatting library, which can round floating point numbers to a specified number of decimal places. However, since PHP's division operation may suffer from infinite decimals or loss of precision, rounding of the divisor is also necessary. Next, we will explain in detail how to use PHP's round() function to divide and round.

How to use the ROUND function in MySQL to intercept the number of decimal places. In MySQL, you can use the ROUND function to intercept the number of decimal places. The ROUND function rounds a number to a specified number of decimal places. The following will introduce you to the use of ROUND function in detail and provide code examples. Syntax: ROUND(X,D)X represents the number to be rounded, and D represents the number of decimal places to be retained. Example of using the ROUND function to intercept the number of decimal places: Suppose there is a table named produc

How to use MySQL's FLOOR function to round down In MySQL, the FLOOR function is used to round down. The FLOOR function is a very useful tool if you need to round down a floating point number or a number with a decimal point to the nearest integer. This article will introduce how to use MySQL's FLOOR function and provide some practical example code. First, let's understand the syntax of the FLOOR function. The syntax of the FLOOR function is as follows: FLOOR(x) where x represents

In PHP, the ceil function is used to round up floating point numbers. This function can very conveniently handle operations on some specific floating point numbers, while also ensuring the accuracy of the data. In this article, we will introduce in detail the method and application scenarios of how to use the ceil function to round up floating point numbers in PHP. 1. Syntax and parameters of ceil function The basic syntax of ceil function is very simple, as shown below: ceil(float$number) This function only accepts one parameter, that is

The intval function in PHP is a function used to convert a variable to an integer type. Its usage is relatively simple, but there are some skills and precautions that need to be mastered. Correct use of the intval function can effectively handle data type conversion issues and avoid errors in the program. The basic usage of the intval function The basic syntax of the intval function is as follows: intval($var,$base=10) where $var represents the variable to be converted to an integer,

Here we will see how to write a one line C function that can round floating point numbers. In order to solve this problem, we have to follow the following steps. Get a number If the number is positive, add 0.5 otherwise, subtract 0.5 Use type conversion to convert the floating point value to an integer Example #include<stdio.h> intmy_round(floatnumber){ return(int)(number<0?number- 0.5:number+0.5);}intmain(){ 

PHP is a popular server-side scripting language that is widely used in website development and application development. In PHP, there are many built-in functions that can help developers simplify the programming process. One of the commonly used functions is the intval function. In this article, we will deeply explore the underlying mechanism of the intval function and use specific code examples to help readers better understand its functions and effects. First, let us understand the basic usage of the intval function. intval function is used
