Table of Contents
ceil — 进一法取整
floor — 舍去法取整
Home Backend Development PHP Tutorial PHP基本功之ceil,floor,round,intval

PHP基本功之ceil,floor,round,intval

Jun 23, 2016 pm 01:09 PM
floor intval round

ceil — 进一法取整

float ceil ( float $value )

返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。

echo ceil(4,3); //5

echo ceil(9.9); //10

floor — 舍去法取整

float floor ( float $value )

返回不大于 value 的下一个整数,将 value 的小数部分舍去取整。floor() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大。

floor() 例子如图:

floor(4.3);//4


echo 'floor(4.3)='.floor(4.3).'<br>';echo 'floor(9.9)='.floor(9.9).'<br>';echo 'ceil(4.3)='.ceil(4.3).'<br>';echo 'ceil(9.9)='.ceil(9.9).'<br>';echo 'round(4.3)='.round(4.3).'<br>';echo 'round(9.9)='.round(9.9).'<br>';exit;
Copy after login

返回结果:

floor(4.3)=4
floor(9.9)=9
ceil(4.3)=5
ceil(9.9)=10
round(4.3)=4
round(9.9)=10

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
How to divide and round using PHP's round() function How to divide and round using PHP's round() function Mar 21, 2023 pm 04:32 PM

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.

What does round mean in php What does round mean in php Mar 10, 2023 am 10:04 AM

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);".

How to use ROUND function to intercept decimal places in MySQL How to use ROUND function to intercept decimal places in MySQL Jul 13, 2023 pm 09:21 PM

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 How to use MySQL's FLOOR function to round down Jul 25, 2023 pm 12:45 PM

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

PHP practical skills: master the correct usage of intval function PHP practical skills: master the correct usage of intval function Mar 09, 2024 pm 09:27 PM

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,

Write a one-line C function to round floating point numbers Write a one-line C function to round floating point numbers Aug 26, 2023 pm 01:53 PM

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(){&nbsp

PHP Programming Guide: How to Customize the Intval Function PHP Programming Guide: How to Customize the Intval Function Mar 11, 2024 am 08:54 AM

In PHP programming, we often use the intval function to convert a variable into an integer value. Although PHP provides this built-in function to implement this function, sometimes we can also customize the intval function according to our own needs. This article will guide you on how to customize the intval function and provide specific code examples. First, let's understand the basic functions of the intval function. The intval function is used to convert a variable to an integer value. If the variable is a string,

PHP Expertise: Exploring the underlying mechanics of the intval function PHP Expertise: Exploring the underlying mechanics of the intval function Mar 09, 2024 pm 02:15 PM

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

See all articles