js 中的 Math.ceil() Math.floor Math.round()

alert(Math.ceil(25.9)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.1)); //26
alert(Math.round(25.9)); //26
alert(Math.round(25.5)); //26
alert(Math.round(25.1)); //25
alert(Math.floor(25.9)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.1)); //25

对于所有介于25和26(不包括26)之间的数值,Math.ceil()始终返回26,因为它执行的是向上舍入。

Math.round()方法只在数值大于等于25.5时返回26;否则返回25。

最后,Math.floor()对所有介于25和26(不包括26)之间的数值都返回25。

时间: 2024-07-28 23:30:30

js 中的 Math.ceil() Math.floor Math.round()的相关文章

Javascript Math ceil()、floor()、round()三个函数的区别

Round是四舍五入的...Ceiling是向上取整..float是向下取整  下面来介绍将小数值舍入为整数的几个方法:Math.ceil().Math.floor()和Math.round(). 这三个方法分别遵循下列舍入规则:◎Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数:◎Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数:◎Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数(这也是我们在数学课上学到的舍入规则).

Jquery Math ceil()、floor()、round()比较与用法

Math.ceil():向上取值 如:Math.ceil(2.1) --  结果为  3 Math.ceil(-2.1)  -- 结果为-2 结论:正入 负舍 Math.floor(): 先下取值 入: Math.ceil(2.1) --  结果为  2 Math.ceil(-2.1)  -- 结果为-3 结论:和ceil()结论相反. 正舍 负入 Math.round:四舍五入 Math.round(2.1) --  结果为  2 Math.round(2.6) --  结果为  3 Math

python中的math.ceil(x)和math.floor(x)

一 math.ceil(x) import math 1.当x为正数时,只要x的小数部分>0就+1 x=5.01 print(math.ceil(x)) #6 x=5.9 print(maht.ceil(x)) #6 2.当x为负数时,舍去小数部分 x=-5.9 print(math.ceil(x)) #-5 x=-5.01 print(math.ceil(x)) #-5 二.math.floor(x) 1.当x为正数时,舍去小数部分 x=5.9 print(math.floor(x)) #5

php取整函数ceil,floor,round,intval函数的区别

开发过程中,遇到数据处理取整的时候,你会用哪个呢,小涛来介绍一下:PHP取整函数有ceil,floor,round,intval,下面详细介绍一下: 1.ceil — 进一法取整说明float ceil ( float $value )返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大.ceil() 例子 <?php echo ceil(4.3); // 5 echo cei

[转]PHP取整函数:ceil,floor,round,intval的区别详细解析

我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大. PHP取整函数例子 1. ceil() 例子 echo ceil(4.3); // 5 echo ceil(9.999); // 10 2.flo

java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))

public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println(Math.abs(-10.4));    //10.4 System.out.println(Math.abs(10.1));     //10.1 /** * ceil天花板的意思,就是返回大的值,注意一些特殊值 */ System.out.println(Math.ceil(-10.1));  

JavaScript里Math对象的ceil()、floor()、round()方法的区别

ceil(x) 官方含义:对一个数进行上舍入.理解:ceiling为天花板的意思,意译为向上取整.即取得大于于等于x的最大整数. floor(x) 官方含义:对一个数进行下舍入.理解:floor为地板的意思,意译为向下取整.即取得小于等于x的最大整数. round() 官方含义: 把一个数四舍五入为最接近的整数.理解:传统意义的四舍五入. 例1: var a = 3.5;document.write(Math.floor(a)) ;document.write(Math.ceil(a)) ;do

PHP取整函数ceil,floor,round,intval的区别

ceil - 进一法取整 float ceil ( float $value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大. floor - 舍去法取整 float floor ( float $value ) 返回不大于 value 的下一个整数,将 value 的小数部分舍去取整.floor() 返回的类型仍然是 float,因为 float 值的范围通常比 i

ceil,floor,trunc,round,sign几个函数在SQL的使用方法

只是在oracle的环境下进行的几个数的测试,在这里只是举例说明,没有理论说明,抱歉. select ceil(1.8) from dual; --结果为1,向上取整select floor (1.8) from dual;--结果为2,向上取整select trunc(1.999333,1) from dual; --结果为1.9,根据精度(1自身设置)取值,取值不舍入select round(1.8992,3) from dual;--结果为1.899,根据精度取值,取值舍入select s

Math ceil() Math.floor(),Math.round()用法

Math.ceil() Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”:如果x是负数,则把小数“舍”. 例: <script type="text/javascript"> document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Ma