JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解

2019-12-24,,

首先还是看看JavaScript: The Definitive Guide, 4th Edition中对三个函数的定义。


Math.ceil(): round a number up


Arguments: Any numeric value or expression


Returns: The closest integer greater than or equal to x.


-----------------------------------------------------------------------------------------------


Math.floor(): round a number down


Arguments: Any numeric value or expression


Returns: The closest integer less than or equal to x.


-----------------------------------------------------------------------------------------------


Math.round(): round to the nearest integer


Arguments: Any number.


Returns: The integer closest to x.


 


以前一直会三个函数的使用产生混淆,现在通过对三个函数的原型定义的理解,其实很容易记住三个函数。


现在做一个总结:


1. Math.ceil()用作向上取整。


2. Math.floor()用作向下取整。


3. Math.round() 我们数学中常用到的四舍五入取整。

您可能感兴趣的文章:

  • Java中Arrays类与Math类详解
  • Java中Math类常用方法代码详解
  • 基于java math API 的详细解释说明
  • JAVA的Random类的用法详解
  • Java中的Random()函数及两种构造方法
  • Java System类详解_动力节点Java学院整理
  • 十分钟速懂java知识点 System类
  • java system类使用方法示例 获取系统信息
  • Java中BigDecimal类的简单用法
  • Java BigDecimal类的使用和注意事项
  • Java Math类、Random类、System类及BigDecimal类用法示例

《JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解.doc》

下载本文的Word格式文档,以方便收藏与打印。