search
Homephp教程PHP源码php 取整函数(floor,ceil,round,intval)

在php中取整函数有四个函数,如floor,ceil,round,intval这几个了,下面我给大家分别介绍它们之间应用实例。

<script>ec(2);</script>

floor 舍去法取整 语法格式:float floor ( float value )

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

 代码如下 复制代码

echo floor(4.3); // 4
echo floor(9.999); // 9


ceil 进一法取整 语法格式: float ceil ( float value )

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

 代码如下 复制代码
echo ceil(4.3); // 5
echo ceil(9.999); // 10

round 对浮点数进行四舍五入

语法:float round ( float val [, int precision] )

 代码如下 复制代码

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


intval---对变数转成整数型态

例子intval()

 代码如下 复制代码

echo intval(4.3);    //4

echo intval(4.6);  // 4  

?>

Statement
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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools