Cirry's Blog

java实现四舍五入且指定小数位数

2019-10-09
技术
java
最后更新:2024-03-22
1分钟
38字
1
package cn.cccc.demo;
2
class MathUtil{
3
private MathUtil(){};
4
5
public static double round(double num, int scale){
6
return Math.round(num * Math.pow(10, scale)) / Math.pow(10, scale);
7
}
8
}
9
public class ThreadDemo {
10
public static void main(String[] args) throws Exception{
11
System.out.println(MathUtil.round(19.46735, 2));
12
}
13
}
本文标题:java实现四舍五入且指定小数位数
文章作者:Cirry
发布时间:2019-10-09
版权声明:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
感谢大佬送来的咖啡☕
alipayQRCode
wechatQRCode