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 x = Math.PI; // Returns PI
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 数字的更多相关文章

  1. javascript ES5 Object对象

    原文:http://javascript.ruanyifeng.com/stdlib/object.html 目录 概述 Object对象的方法 Object() Object.keys(),Obje ...

  2. JavaScript之Object拆解

    转载烦请注明原文链接: https://github.com/Xing-Chuan/blog/blob/master/JavaScript/JavaScript%E4%B9%8BObject%E6%8 ...

  3. 【JavaScript 从零开始】 数字 文本 包装对象

    JavaScript中的算术运算 JavaScript 还自称更加复杂的算术运算,这些复杂的运算通过作为Math对象的属性定义的函数和常量来实现: Math.pow(2,53) //=>9007 ...

  4. JavaScript 中的数字和日期类型

    本章节介绍如何掌握Javascript里的数字和日期类型 数字EDIT 在 JavaScript 里面,数字都是双精度浮点类型的 double-precision 64-bit binary form ...

  5. 从头开始学JavaScript (十一)——Object类型

    原文:从头开始学JavaScript (十一)--Object类型 一.object类型 一个object就是一系列属性的集合,一个属性包含一个名字(属性名)和一个值(属性值). object对于在应 ...

  6. JavaScript 金额、数字、千分位、千分位、保留几位小数、舍入舍去、支持负数

    JavaScript 金额.数字 千分位格式化.保留指定位数小数.支持四舍五入.进一法.去尾法 字段说明: number:需要处理的数字: decimals:保留几位小数,默认两位,可不传: dec_ ...

  7. JavaScript中Object.prototype.toString方法的原理

    在JavaScript中,想要判断某个对象值属于哪种内置类型,最靠谱的做法就是通过Object.prototype.toString方法. ? 1 2 var arr = []; console.lo ...

  8. 【WIP】客户端JavaScript Web Object

    创建: 2017/10/11   更新: 2017/10/14 标题加上[WIP],增加[TODO] 更新: 2018/01/22 更改标题 [客户端JavaScript Web Object, UR ...

  9. 松软科技web课堂:JavaScript Math 对象

    JavaScript Math 对象允许您对数字执行数学任务. 实例 Math.PI; // 返回 3.141592653589793 Math.round() Math.round(x) 的返回值是 ...

随机推荐

  1. set练习

    #include <iostream> #include <set> #include <vector> using namespace std; int main ...

  2. 【LeetCode】Number of Islands

    Number of Islands 问题描写叙述 Given a 2d grid map of '1's (land) and '0's (water), count the number of is ...

  3. 【cocos2dx中Node类getParent和getChildByTag()】学习体会

    參考http://cn.cocos2d-x.org/doc/cocos2d-x-3.0/d3/d82/classcocos2d_1_1_node.html 当中和child.parent有关的成员函数 ...

  4. Linux echo 显示内容颜色

    Linux echo 显示内容颜色 https://www.cnblogs.com/kimbo/p/6816566.html #字体颜色:30m-37m 黑.红.绿.黄.蓝.紫.青.白 str=&qu ...

  5. Eclipse CDT 插件列表

    http://www.bestplugins.com/software/eclipse-c-plugin.html

  6. Pandas DataFrame笔记

    1.属性方式,可以用于列,不能用于行 2.可以用整数切片选择行,但不能用单个整数索引(当索引不是整数时) 3.直接索引可以使用列.列集合,但不能用索引名索引行 用iloc取行,得到的series: d ...

  7. 浅谈压缩感知(十四):傅里叶矩阵与小波变换矩阵的MATLAB实现

    主要内容: 傅里叶矩阵及其MATLAB实现 小波变换矩阵及其MATLAB实现  傅里叶矩阵及其MATLAB实现 傅里叶矩阵的定义:(来源: http://mathworld.wolfram.com/F ...

  8. 变址values(, %edi, 4)和间址4(%edi)

    <汇编语言程序设计>Richard Blum著:5.2.4 在内存和寄存器之间传送数据   使用变址的内存位置: 可以在一个命令中指定把多个值存放到内存中: values:     .in ...

  9. 解决Maven报Plugin execution not covered by lifecycle configuration

    来自:http://blog.csdn.net/xxd851116/article/details/25197373 环境     eclipse 4.3.0     maven 3.0.4     ...

  10. SpringMVC对日期类型的转换@ResponseBody返回的DateTime是long类型

    目前,多数web开发这都在使用Spring的框架.但是这个框架有个 @ResponseBody 注解返回json时,日期格式默认显示为时间戳. 而我们页面展示的时候一般都是以下格式: yyyy-MM- ...