/**
* 指定保留n位小数
* @param str
* @param keepType "#0.##" 假如两位
* @param keepLength ".00" 假如两位
* @return
*/
def formatDouble(Double str,String keepType,String keepLength){
//定义一个数字格式化对象,格式化模板为".#",即保留1位小数.
DecimalFormat b = new DecimalFormat(keepType);
b.applyPattern(keepLength);
b.setRoundingMode(RoundingMode.FLOOR); //不四舍五入
String resultData= b.format(str);
return resultData
}
转载于:https://my.oschina.net/zhenguoguan/blog/138639