硬汉工作室

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz

[javascript] javascript里的Math对象

[复制链接]
发表于 2024-8-27 13:55:05 | 显示全部楼层 |阅读模式
Math无需实例化,都是类似静态的方法。

Math.PI; // 返回圆周率3.141592653589793
Math.abs(-10); // 返回参数的绝对值

Math.ceil(4.1); // 向上取整,返回5

Math.floor(4.8); // 向下取整,返回4

Math.round(4.5); // 四舍五入,返回5

Math.random(); // 返回0-1之间的随机数,[0, 1),如:0.43559456429386056

如果返回1-10之间的随机数呢?
Math.ceil(Math.random() * 10)

如果返回0-10之间的随机数呢?
Math.floor(Math.random() * 11)

参考链接:https://www.runoob.com/jsref/jsref-obj-math.html





有关PHP系统、Discuz或网站等各种问题,可以联系QQ1069971363寻求付费支持
Discuz插件商店:http://addon.dismall.com/?@56030.developer
回复

使用道具 举报

QQ|Archiver|手机版|小黑屋|硬汉工作室 ( 冀ICP备13021567号-9 )

GMT+8, 2025-3-12 18:58 , Processed in 0.051774 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表