这个工具比较简单,因此不多介绍。直接看段代码吧。
package test;
import org.apache.commons.math.util.MathUtils;
public class TestMath {
public static void main(String[] args) {
System.out.println(20.0d / 3.0d);
// 保留3位小数,四舍五入
System.out.println(MathUtils.round(20.0d / 3.0d, 3));
System.out.println(MathUtils.round(200.0d / 3.0d, 3));
}
}
/*
6.666666666666667
6.667
66.667
*/