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

    Math.PI       记录的圆周率
    Math.E        记录e的常量
    Math.abs       求绝对值
    Math.ceil          得到不小于某数的最大整数
    Math.floor         得到不大于某数的最大整数
    Math.IEEEremainder  求余
    Math.max         求两数中最大
    Math.min          求两数中最小
    Math.sqrt          求开方
    Math.pow(double a,double b) 求a的b次方, 抛出ArithmeticException处理溢出异常
    Math.exp          求e的任意次方
    Math.log10       以10为底的对数
    Math.log           自然对数
    Math.rint         求距离某数最近的整数(可能比某数大,也可能比它小)
    Math.round        同上,返回int型或者long型(上一个函数返回double型)
    Math.random          返回0,1之间的一个随机数

      //abs
        Math.abs(-10.4);    //10.4   
        Math.abs(10.1);     //10.1   
    
        //ceil     
        Math.ceil(-10.1);   //-10.0   
        Math.ceil(10.7);    //11.0   
        Math.ceil(0.0);     //0.0   
        Math.ceil(-0.0);    //-0.0   
    
        //floor
        Math.floor(-10.1);  //-11.0  
        Math.floor(10.7);   //10.0   
        Math.floor(0.0);    //0.0   
        Math.floor(-0.0);   //-0.0   
    
        //max
        Math.max(-10.1, -10);   //-10.0   
        Math.max(10.7, 10);     //10.7   
        Math.max(0.0, -0.0);    //0.0   
    
        //random 
        Math.random();  //0.08417657924317234   
        Math.random();  //0.43527904004403717   
    
        //rint 
        Math.rint(10.1);    //10.0   
        Math.rint(11.5);    //12.0   
        Math.rint(10.5);    //10.0   
    
        //round 
        Math.round(10.1);   //10   
        Math.round(-10.5);  //-10   
        Math.round(-10.6); //-11   
    
      //pow
      Math.pow(64,1/3); //1,1/3值为0,任何数的0次方都是1
      Math.pow(64,1.0/3); //结果不是1了
  • 相关阅读:
    leetcode59
    leetcode95
    leetcode96
    leetcode787
    leetcode150
    leetcode165
    leetcode739
    快速搭建:Djangorest-framework的restful项目
    编写部署用到的部分shell脚本收集
    pandas:dataframe删除某些不为non的行
  • 原文地址:https://www.cnblogs.com/whatarewords/p/10774246.html
Copyright © 2011-2022 走看看