Java、Android中Math类中常用方法的简单介绍

Math.PI 记录的圆周率 PI = 3.141592653589793;

Math.E 记录e的常量 E = 2.718281828459045;

/**
     * Returns the absolute value of the argument.
     * <p>
     * Special cases:
     * <ul>
     * <li>{@code abs(-0.0) = +0.0}</li>
     * <li>{@code abs(+infinity) = +infinity}</li>
     * <li>{@code abs(-infinity) = +infinity}</li>
     * <li>{@code abs(NaN) = NaN}</li>
     * </ul>
     */

Math.abs() 求绝对值

/**
     * Returns the closest double approximation of the sine of the argument. The
     * returned result is within 1 ulp (unit in the last place) of the real
     * result.
     * <p>
     * Special cases:
     * <ul>
     * <li>{@code sin(+0.0) = +0.0}</li>
     * <li>{@code sin(-0.0) = -0.0}</li>
     * <li>{@code sin(+infinity) = NaN}</li>
     * <li>{@code sin(-infinity) = NaN}</li>
     * <li>{@code sin(NaN) = NaN}</li>
     * </ul>
     *
     * @param d
     *            the angle whose sin has to be computed, in radians.
     * @return the sine of the argument.
     */

Math.sin() 正弦函数

/**
     * Returns the closest double approximation of the arc sine of the argument
     * within the range {@code [-pi/2..pi/2]}. The returned result is within 1
     * ulp (unit in the last place) of the real result.
     * <p>
     * Special cases:
     * <ul>
     * <li>{@code asin((anything > 1)) = NaN}</li>
     * <li>{@code asin((anything < -1)) = NaN}</li>
     * <li>{@code asin(NaN) = NaN}</li>
     * </ul>
     *
     * @param d
     *            the value whose arc sine has to be computed.
     * @return the arc sine of the argument.
     */

Math.asin()反正弦函数

Math.cos()余弦函数
Math.acos()反余弦函数
Math.tan()正切函数
Math.atan()反正切函数
Math.atan2()商的反正切函数
Math.toDegrees()弧度转换为角度
Math.toRadians()角度转化为弧度
Math.ceil()得到不小于某数的最大整数
Math.floor()得到不小于某数的最大值
例如: Math.floor(12.7)=12.0
Math.ceil(12.7)=13.0
ceil()是天花板,即向上取值,floor()是地板,向下取值。round()是四舍五入

Math.IEEEremaiinder()求余
Math.maz()求两个数最大值
Math.min()求两个数最小值
Math.sqrt()求开方
Math.pow()求某数的任意次方,抛出ArithmeticExction处理溢出的异常
Math.sqrt(x)平方根
Math.pow(x,y):x的y次方

Math.exp()求e的任意次方
Math.log10 求以10为底的对数
Math.log()求自然对数
Math.rint() 求距离某数最近的整数(可能比某数大,也可能比它小)
Math.round() 四舍五入
Math.random()返回(0,1)之间的一个随机数

BigInteger bi1=new BigInteger(“12345678901234567890”);
BigInteger bi2=BigInteger.valueOf(123L)
bi1=bil1.add(bi2);//b1+b2;
bi1=bi1.multiply(bi2);//b1*b2;
bi1=bi1.subtract(bi2);//b1-b2;
bil1=bi1.divide(bi2);//b1/b2;

java.math.BigDecimal(大浮点数)
BigDecimal bd=new BigDecimal(“3.1415926”);
bg=bd.setScale(2,BigDeciamal.ROUND_DOWN);取3.1415926小数点后面两位

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值