javaSE_常用Math方法

Math.PI  // 3.141592653589793

// 弧度转角度

Math.toDegrees(Math.PI);// 180.0

// 角度转弧度

Math.toRadians(180);// 3.141592653589793

Math.sin(Math.toRadians(90));// 1.0

Math.cos(Math.toRadians(180));// -1.0

Math.tan(Math.toRadians(45));// 0.9999999999999999

// 向下取整

Math.floor(32.356);// 32.0

// 向上取整

Math.ceil(32.356);// 31.0

// 四舍五入(保留整数)

Math.round(32.356);// 32

// 四舍五入(自定义小数位数)

String sData = new DecimalFormat("#.##").format(32.356);

System.out.println(sData); // 32.36

注:#.##0.00的区别:

00是几个0就一定有这么多位小数,不够使用0补全;

##如果最后是0则省略。

System.out.println(new DecimalFormat("#.##").format(21.2));// 21.2

System.out.println(new DecimalFormat("0.00").format(21.2));// 21.20

// 平方根

Math.sqrt(2);// 1.4142135623730951

// 最小值

Math.min(2, 5);// 2

// 最大值

Math.max(2, 5);// 5

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值