1.保留小数
java四舍五入保留2位小数
public static String test(double a) {
DecimalFormat df=new DecimalFormat("0.00");//设置保留位数
return df.format(a);
}
scala四舍五入保留2位小数
def doubleSet(dou: Double) = {
(dou * 100).formatted("%.2f")
}
scala不进行四舍五入保留2位小数
def doubleSet(dou: Double) = {
val dous = (dou * 100).toString.split("\\.", -1)
(dous(0) + "." + (dous(1) + "00").substring(0, 2))
}