美文网首页
Math方法总结

Math方法总结

作者: 温梦丽 | 来源:发表于2017-11-13 16:22 被阅读0次

1.min()和max()方法
找出一组数值中的最小和最大值

Math.min(5,4,3,2,1);
Math.max(5,4,3,2,1);

2.舍入方法
Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;
Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;
Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数;

Math.ceil(23.6);//24
Math.floor(23.6);//23
Math.round(23.6);//24

3.random()方法
Math.random()方法返回介于0到1之间一个随机数,不包括0和1。如果想大于这个范围的话,可以套用一下公式:
值 = Math.floor(Math.random() * 总数 + 第一个值)

Math.floor(Math.random()*10+1);//随机产生一个1-10的数。
Math.floor(Math.random()*10+5);//随机产生一个5-14的数。

4.其他方法


image.png

相关文章

  • Math方法总结

    1.min()和max()方法找出一组数值中的最小和最大值 2.舍入方法Math.ceil()执行向上舍入,即它总...

  • python内置函数

    math模块 在使用前导入math模块 import math 常用方法 math.pow()方法 math.p...

  • JS获取两个数之间的任意随机数

    方法一 方法二 Math.round(),Math.ceil(),Math.floor()的区别1.Math.ro...

  • math包总结

    开发中使用中使用到了math这个包,总结一下math包的主要方法与功能。 func Float32bits 函数返...

  • python各数据类型方法专题(一)待续......

    本人深知学习一门语言时基础的重要性,所以在此重新总结各类方法 Nummber 1.math模块(由于math模块方...

  • JavaScript Math 对象方法总结

    文章摘自 菜鸟教程类似文章推荐:JavaScript String 对象方法总结JavaScript Array ...

  • Math对象

    Math对象的属性 Math对象的方法

  • JS笔记14:数学对象Math

    其他方法多记忆Math Math其他属性或方法:腾讯云-开发者社区-JavaScript-Math[https:/...

  • Math 对象

    Math 对象用于执行数学任务 Math 对象属性 Math 对象方法 abs() abs() 方法可返回数的绝对...

  • Math和Date

    Math对象 Math对象 里面提供的方法,可以帮助我们解决算术问题 提供的方法: Math.random() 返...

网友评论

      本文标题:Math方法总结

      本文链接:https://www.haomeiwen.com/subject/sjezmxtx.html