JavaScript Math Object 数字
JavaScript Math Object
Math Object
The Math object allows you to perform mathematical tasks.
Math is not a constructor. All properties/methods of Math can be called by using Math as an object, without creating it.
Syntax
var y = Math.sqrt(16); // Returns the square root of 16
For a tutorial about the Math object, read our JavaScript Math Object tutorial.
Math Object Properties
| Property | Description |
|---|---|
| E | Returns Euler's number (approx. 2.718) |
| LN2 | Returns the natural logarithm of 2 (approx. 0.693) |
| LN10 | Returns the natural logarithm of 10 (approx. 2.302) |
| LOG2E | Returns the base-2 logarithm of E (approx. 1.442) |
| LOG10E | Returns the base-10 logarithm of E (approx. 0.434) |
| PI | Returns PI (approx. 3.14) |
| SQRT1_2 | Returns the square root of 1/2 (approx. 0.707) |
| SQRT2 | Returns the square root of 2 (approx. 1.414) |
Math Object Methods
| Method | Description |
|---|---|
| abs(x) | Returns the absolute value of x |
| acos(x) | Returns the arccosine of x, in radians |
| asin(x) | Returns the arcsine of x, in radians |
| atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |
| atan2(y,x) | Returns the arctangent of the quotient of its arguments |
| ceil(x) | Returns x, rounded upwards to the nearest integer |
| cos(x) | Returns the cosine of x (x is in radians) |
| exp(x) | Returns the value of Ex |
| floor(x) | Returns x, rounded downwards to the nearest integer |
| log(x) | Returns the natural logarithm (base E) of x |
| max(x,y,z,...,n) | Returns the number with the highest value |
| min(x,y,z,...,n) | Returns the number with the lowest value |
| pow(x,y) | Returns the value of x to the power of y |
| random() | Returns a random number between 0 and 1 |
| round(x) | Rounds x to the nearest integer |
| sin(x) | Returns the sine of x (x is in radians) |
| sqrt(x) | Returns the square root of x |
| tan(x) | Returns the tangent of an angle |
实例:
<html>
<script type="text/javascript">
alert(Math.round(2.3));//四舍五入,2
alert(Math.random()*10);//1-9,5.369114940257843
alert(Math.min(5,10));//判断数字哪个较小,5
alert(Math.max(10,6));//数字哪个较大,10
</script>
</html>
JavaScript Math Object 数字的更多相关文章
- javascript ES5 Object对象
原文:http://javascript.ruanyifeng.com/stdlib/object.html 目录 概述 Object对象的方法 Object() Object.keys(),Obje ...
- JavaScript之Object拆解
转载烦请注明原文链接: https://github.com/Xing-Chuan/blog/blob/master/JavaScript/JavaScript%E4%B9%8BObject%E6%8 ...
- 【JavaScript 从零开始】 数字 文本 包装对象
JavaScript中的算术运算 JavaScript 还自称更加复杂的算术运算,这些复杂的运算通过作为Math对象的属性定义的函数和常量来实现: Math.pow(2,53) //=>9007 ...
- JavaScript 中的数字和日期类型
本章节介绍如何掌握Javascript里的数字和日期类型 数字EDIT 在 JavaScript 里面,数字都是双精度浮点类型的 double-precision 64-bit binary form ...
- 从头开始学JavaScript (十一)——Object类型
原文:从头开始学JavaScript (十一)--Object类型 一.object类型 一个object就是一系列属性的集合,一个属性包含一个名字(属性名)和一个值(属性值). object对于在应 ...
- JavaScript 金额、数字、千分位、千分位、保留几位小数、舍入舍去、支持负数
JavaScript 金额.数字 千分位格式化.保留指定位数小数.支持四舍五入.进一法.去尾法 字段说明: number:需要处理的数字: decimals:保留几位小数,默认两位,可不传: dec_ ...
- JavaScript中Object.prototype.toString方法的原理
在JavaScript中,想要判断某个对象值属于哪种内置类型,最靠谱的做法就是通过Object.prototype.toString方法. ? 1 2 var arr = []; console.lo ...
- 【WIP】客户端JavaScript Web Object
创建: 2017/10/11 更新: 2017/10/14 标题加上[WIP],增加[TODO] 更新: 2018/01/22 更改标题 [客户端JavaScript Web Object, UR ...
- 松软科技web课堂:JavaScript Math 对象
JavaScript Math 对象允许您对数字执行数学任务. 实例 Math.PI; // 返回 3.141592653589793 Math.round() Math.round(x) 的返回值是 ...
随机推荐
- SQLServer 数据库镜像+复制切换方案
目标: 主机做了Mirror和Replication,当主机出现问题时,Replication和Mirror实现自动的故障转移(Mirror 和Replication都切换到备机,而当主机 重新启动后 ...
- 【cocos2dx中Node类getParent和getChildByTag()】学习体会
參考http://cn.cocos2d-x.org/doc/cocos2d-x-3.0/d3/d82/classcocos2d_1_1_node.html 当中和child.parent有关的成员函数 ...
- MongoDB分页的Java实现和分页需求的思考
前言 传统关系数据库中都提供了基于row number的分页功能,切换MongoDB后,想要实现分页,则需要修改一下思路. 传统分页思路 假设一页大小为10条.则 //page 1 1-10 //pa ...
- IDEA 禁止自动导入引用包 取消import包
http://www.oschina.net/question/2010061_226765 我想拷贝一小段代码,或者我就是不想引入拷贝来的包,我该怎么取消掉idea的自动导入import包呢? 找到 ...
- 鼠标上下滚动支持combobox选中
首先需要jquery插件来支持: 1.代码SVN检出https://github.com/jquery/jquery-mousewheel 2.点击这里下载jquery.mousewheel.zip ...
- 优化MySQL开启skip-name-resolve参数时显示“ignored in --skip-name-resolve mode.”Warning解决方法
转自:http://blog.csdn.net/yiluoak_47/article/details/53381282 参数用途: skip-name-resolve #禁止MySQL对外部连接进行D ...
- SDE注册版本失败,仅支持一个空间列
如果直接编辑SDE要素类与要素可以不需要版本,使用默认版本,如果要让用户通过界面编辑,即使用开启编辑.保存编辑和停止编辑,就需要注册为版本,而在注册版本弹出如下错误: 正如错误所说,一个要素类或shp ...
- Multipathing for Software iSCSI
see also:http://www.vmware.com/files/pdf/techpaper/vmware-multipathing-configuration-software-iSCSI- ...
- python获取命令行参数 启动文件
import sys # python D:\MARK\temp.py m1 start 9090 print(sys.argv) # ['D:\\MARK\\temp.py', 'm1', 'sta ...
- 演示一下:rm -rf /