js对于数字的操作

Math.ceil(number):向上取整 实例: Math.ceil(5.02)得出6

与之相反的是:

Math.floor(number):取整数部分 实例:Math.floor(5.02)得出5

Math.round(number),四舍五入。实例:Math.round(5.49)===5,Math.round(5.50)===5

Math.PI 圆周率值:3.1415926.。。

Math.random() :输出0-1之间一个随机数

number.toPrecision(count):count表示要保留整个数字的位数,并会把数字转化为字符串,如3.12.toPrecision(2)==="3.1",3.12.toPrecision(4)==="3.120"

number.toFixed(count),count表示要保留的小数点后的位数,并会把数字转化为字符串,如3.12.toFixed(4)==="3.1200",3.12.toFixed(1)==="3.1"

posted on 2012-11-14 15:12  胡布内尔  阅读(288)  评论(0编辑  收藏  举报