Java-数据字符串进行四舍五入

/**
 * 对数字字符串 不  四舍五入处理
 *
 * @param str   处理参数
 * @param scale 保留小数位数
 * @return 返回值
 */
public class RoundNoOfUtil {

    public static String RoundNoOf(String str, int scale) {
        try {
            // 输入精度小于0则抛出异常
            if (scale < 0) {
                throw new IllegalArgumentException("The scale must be a positive integer or zero");
            }

            // 取得数值
            BigDecimal b = new BigDecimal(str);
            // 取得数值1
            BigDecimal one = new BigDecimal("1");
            // 原始值除以1,保留scale位小数,进行四舍五入
            return b.divide(one, scale, BigDecimal.ROUND_DOWN).toString();
        }catch (Exception e){
            e.printStackTrace();
        }
        return str;

    }
}