js中Math對象的方法

來源:互聯網
上載者:User

1.丟棄小數部分,保留整數部分parseInt(5/2)2.向上取整,有小數就整數部分加1Math.ceil(5/2)3,四捨五入.Math.round(5/2)4,向下取整Math.floor(5/2)Math 對象的方法FF: Firefox, N: Netscape, IE: Internet Explorer方法 描述 FF N IE abs(x) 返回數的絕對值 1 2 3 acos(x) 返回數的反餘弦值 1 2 3 asin(x) 返回數的反正弦值 1 2 3 atan(x) 以介於 -PI/2 與 PI/2 弧度之間的數值來返回 x 的反正切值 1 2 3 atan2(y,x) 返回從 x 軸到點 (x,y) 的角度(介於 -PI/2 與 PI/2 弧度之間) 1 2 3 ceil(x) 對一個數進行上舍入。 1 2 3 cos(x) 返回數的餘弦 1 2 3 exp(x) 返回 e 的指數。 1 2 3 floor(x) 對一個數進行下舍入。 1 2 3 log(x) 返回數的自然對數(底為e) 1 2 3 max(x,y) 返回 x 和 y 中的最高值 1 2 3 min(x,y) 返回 x 和 y 中的最低值 1 2 3 pow(x,y) 返回 x 的 y 次冪 1 2 3 random() 返回 0 ~ 1 之間的隨機數 1 2 3 round(x) 把一個數四捨五入為最接近的整數 1 2 3 sin(x) 返回數的正弦 1 2 3 sqrt(x) 返回數的平方根 1 2 3 tan(x) 返回一個角的正切 1 2 3 toSource() 代表對象的原始碼 1 4 - valueOf() 返回一個 Math 對象的原始值   1. Math.abs(num) : 返回num的絕對值2. Math.acos(num) : 返回num的反餘弦值3. Math.asin(num) : 返回num的反正弦值4. Math.atan(num) : 返回num的反正切值5. Math.atan2(y,x) : 返回y除以x的商的反正切值6. Math.ceil(num) : 返回大於num的最小整數7. Math.cos(num) : 返回num的餘弦值8. Math.exp(x) : 返回以自然數為底,x次冪的數9. Math.floor(num) : 返回小於num的最大整數10.Math.log(num) : 返回num的自然對數11.Math.max(num1,num2) : 返回num1和num2中較大的一個12.Math.min(num1,num2) : 返回num1和num2中較小的一個13.Math.pow(x,y) : 返回x的y次方的值14.Math.random() : 返回0到1之間的一個隨機數15.Math.round(num) : 返回num四捨五入後的值16.Math.sin(num) : 返回num的正弦值17.Math.sqrt(num) : 返回num的平方根18.Math.tan(num) : 返回num的正切值19.Math.E : 自然數(2.718281828459045)20.Math.LN2 : 2的自然對數(0.6931471805599453)21.Math.LN10 : 10的自然對數(2.302585092994046)22.Math.LOG2E : log 2 為底的自然數(1.4426950408889634)23.Math.LOG10E : log 10 為底的自然數(0.4342944819032518)24.Math.PI : π(3.141592653589793)25.Math.SQRT1_2 : 1/2的平方根(0.7071067811865476)26.Math.SQRT2 : 2的平方根(1.4142135623730951)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.