向下取整:
Math.floor
例如:Math.floor (1.1), Math.floor (-1.1)

向上取整:
Math.ceil
例如:Math.ceil (1.1), Math.ceil (-1.1)

向零取整(正数向下,负数向上):
Math.trunc
例如:Math.trunc (1.1), Math.trunc (-1.1)
parseInt
例如:parseInt (1.1), parseInt (-1.1)
~~
例如:~~ 1.1, ~~ -1.1

四舍五入:
Math.round
例如:Math.round (1.4), Math.round (1.5), Math.round (-1.4), Math.round
(-1.5), Math.round (-1.6)
(1.4).toFixed (), (1.5).toFixed (), (-1.4).toFixed (), (-1.5).toFixed
(), (-1.6).toFixed ()
将小数转为文本,参数为四舍五入保留小数位数,默认为零;参数为负情况下,取值与Math.round略有差异

例如:(1.4).toFixed (), (1.5).toFixed (), (-1.4).toFixed (), (-1.5).toFixed
(), (-1.6).toFixed ()

技术
今日推荐
阅读数 169428
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信