<转> js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
2017-04-17 15:48
597 查看
一、Math.round
作用:四舍五入,返回参数+0.5后,向下取整。
如:
Math.round(5.57) //返回6
Math.round(2.4) //返回2
Math.round(-1.5) //返回-1
Math.round(-5.8) //返回-6
二、parseInt
作用:解析一个字符串,并返回一个整数,这里可以简单理解成返回舍去参数的小数部分后的整数。
如:
parseInt(5.57) //返回5
parseInt(2.4) //返回2
parseInt(-1.5) //返回-1
parseInt(-5.8) //返回-5
三、Math.floor
作用:返回小于等于参数的最大整数。
如:
Math.floor(5.57) //返回5
Math.floor(2.4) //返回2
Math.floor(-1.5) //返回-2
Math.floor(-5.8) //返回-6
四、Math.ceil
作用:返回大于等于参数的最小整数
Math.ceil(5.57) //返回6
Math.ceil(2.4) //返回3
Math.ceil(-1.5) //返回-1
Math.ceil(-5.8) //返回-5
作用:四舍五入,返回参数+0.5后,向下取整。
如:
Math.round(5.57) //返回6
Math.round(2.4) //返回2
Math.round(-1.5) //返回-1
Math.round(-5.8) //返回-6
二、parseInt
作用:解析一个字符串,并返回一个整数,这里可以简单理解成返回舍去参数的小数部分后的整数。
如:
parseInt(5.57) //返回5
parseInt(2.4) //返回2
parseInt(-1.5) //返回-1
parseInt(-5.8) //返回-5
三、Math.floor
作用:返回小于等于参数的最大整数。
如:
Math.floor(5.57) //返回5
Math.floor(2.4) //返回2
Math.floor(-1.5) //返回-2
Math.floor(-5.8) //返回-6
四、Math.ceil
作用:返回大于等于参数的最小整数
Math.ceil(5.57) //返回6
Math.ceil(2.4) //返回3
Math.ceil(-1.5) //返回-1
Math.ceil(-5.8) //返回-5
相关文章推荐
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
- Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结【转】
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整小结
- parseInt()、Math.round()、Math.floor()、Math.ceil()四种取整方法的区别
- js中Math之random,round,ceil,floor的用法总结
- js中Math之random,round,ceil,floor的用法总结
- js中Math之random,round,ceil,floor的用法总结
- js的向上取整(Math.ceil)向下取整(Math.floor)四舍五入(Math.round)
- JS中Math之random,round,ceil,floor的用法总结
- js中Math之random,round,ceil,floor的用法总结
- Javascript Math 中常用函数<一>--ceil(),floor(),round()
- Java Math.floor(),Math.round(),Math.ceil(), num.toFixed()总结(转+编)
- java中Math之random,round,ceil,floor的用法总结
- JAVA除法保留小数点后两位的两种方法 Java Math的 floor,round和ceil的总结
- Java Math的 floor,round和ceil的总结
- Math类中ceil、floor、round取整介绍
- Java Math的 floor,round和ceil的总结