java之Math

一、Math类
java.lang.Math提供了一系列静态方法用于科学计算;其方法的參数和返回值类型一般为double型。
abs     绝对值
acos,asin,atan,cos,sin,tan  三角函数
sqrt     平方根
pow(double a,doble b)     a的b次幂
log    自然对数
exp    e为底指数
max(double a,double b)
min(double a,double b)
random()      返回0.0到1.0的随机数
long round(double a)     double型数据a转换为long型(四舍五入)
toDegrees(double angrad)     弧度—>角度
toRadians(double angdeg)     角度—>弧度

二、BigInteger类
Integer类作为int的包装类,能存储的最大整型值为2^31-1,BigInteger类的数值范围较Integer类的数字
范围要大得多,能够支持随意精度的整数。


①构造器
BigInteger(String val)
经常用法
public BigInteger abs()
public BigInteger add(BigInteger val)
public BigInteger subtract(BigInteger val)
public BigInteger multiply(BigInteger val)
public BigInteger divide(BigInteger val)
public BigInteger remainder(BigInteger val)
public BigInteger pow(int exponent)
public BigInteger[] divdeAndRemainder(BigInteger val)

三、BigDecimal类
一般的Float类和Double类能够用来做科学计算或project计算。但在商业计算中,要求数字精度比較高,故用到java.math.BigDecimal类。BigDecimal类支持不论什么精度的定点数。


构造器
public BigDecimal(double val)
public BigDecimal(String val)
经常用法
public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode)

原文地址:https://www.cnblogs.com/yxysuanfa/p/6738846.html