博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【JS】引用类型之Math
阅读量:7230 次
发布时间:2019-06-29

本文共 623 字,大约阅读时间需要 2 分钟。

Math对象包含了一些计算中可能会用到的一些特殊值,例如:Math.PI代表圆周率π。

常用方法:

1、max和min

取最大值和最小值

var max = Math.max(3, 54, 32, 16);alert(max);    //54var min = Math.min(3, 54, 32, 16);alert(min);    //3var arr = [3, 54, 32, 16];alert(Math.max.apply(Math,arr)); //54  使用这种方法可以让max和min支持传入数组对象

 2、舍入函数(ceil()、floor()、round())

//ceil:只要有小数就进1alert(Math.ceil(25.9));     //26alert(Math.ceil(25.5));     //26alert(Math.ceil(25.1));     //26//round:四舍五入alert(Math.round(25.9));    //26alert(Math.round(25.5));    //26alert(Math.round(25.1));    //25//floor:忽略小数点alert(Math.floor(25.9));    //25alert(Math.floor(25.5));    //25alert(Math.floor(25.1));    //25

 

 

转载地址:http://vedfm.baihongyu.com/

你可能感兴趣的文章
【微信事业群】趣味面试算法题
查看>>
保守的国美再一次进击社交电商,前途未卜?
查看>>
git
查看>>
Python学习教程(Python学习路线):Python 3—手动创建迭代器
查看>>
说说如何在 Virtual Box 中新建 CentOS 虚拟机
查看>>
Cordova + Vue 实现点击两次退出应用
查看>>
JAVA 多用户商城系统b2b2c-Spring Cloud Stream 介绍
查看>>
spring cloud构建互联网分布式微服务云平台-SpringCloud集成项目简介
查看>>
基于房源的画像分析
查看>>
80% UI 初学者走过的弯路,你走了几条?
查看>>
文档和元素的几何滚动
查看>>
php 设计模式
查看>>
Java springcloud B2B2C o2o多用户商城 springcloud架构(八)springboot整合mongodb
查看>>
3年工作经验的Java程序员面试经过
查看>>
Mysql 批量写入数据,对于这类性能问题,你是如何优化的
查看>>
MySQL无法启动几种常见问题小结
查看>>
阿里CTO:阿里所有技术和产品输出都将必须通过阿里云进行
查看>>
更好用的集群限流功能,Sentinel 发布 v1.4.2
查看>>
Python(生成执行文件)
查看>>
redis安装配置 - ttlsa教程系列之redis
查看>>