zoukankan      html  css  js  c++  java
  • Math常用方法

    abs() 可以返回绝对值

    //console.log( Math.abs(+10) );   //10
    //console.log( Math.abs(-10) );   //10
    

    ceil() 对一个数进行上舍入

    //console.log( Math.ceil(5.3) );    //6
    //console.log( Math.ceil(-5.3) );    //-5
    

    floor() 对一个数进行下舍入

    //console.log( Math.floor(5.9) );   //5
    //console.log( Math.floor(-5.9) );  //-6
    

    max(i,j) 返回两个指定的数中较大的那个数

    //console.log( Math.max(10,9) );      //10
    

    min(i,j) 返回两个指定的数中较小的那个数

    //console.log( Math.min(10,9) );      //9
    

    pow() 返回x的y次幂的值

    //console.log( Math.pow(3,2) );		//9
    //console.log( Math.pow(3,3) );		//27  
    

    sqrt() 返回一个数的平方根

    //console.log( Math.sqrt(4) ) 		//2
    //console.log( Math.sqrt(16) ) 		//4
    

    round() 四舍五入为一个整数

    //console.log( Math.round(5.6) );		//6
    //console.log( Math.round(5.3) );     //5
    

    random()

    console.log( Math.random() * 2 );  //可以无限接近2,但不会等于2
    console.log( Math.random()  );     //可以无限接近1,但不会等于1
    
    function Round( max,min ){
    	return Math.round( Math.random() * (max-min) + min );
    }
    console.log( Round(10,1) );    //10--1之间任意一个数
    

    4位随机数

        function getRand(min,max){
        return Math.round( Math.random()*(max-min) + min );
    }
    
    for (var i=0; i<4; i++) {
    	console.log(getRand(0, 9))
    }
  • 相关阅读:
    [置顶] 十年博客行
    计算机编程语言年史
    初步认知MySQL metadata lock(MDL)
    Oracle语句优化规则(二)
    正则表达式
    sql server中的 SET NOCOUNT ON 的含义
    SQO (标准查询运算符)方法 & Linq To Object
    C# 扩展
    特性
    C#之泛型
  • 原文地址:https://www.cnblogs.com/lhh-bky/p/7992922.html
Copyright © 2011-2022 走看看