分转元并去掉小数点后面无用值 public static String convertFen2Yuan(String fen) { BigDecimal fenAmt = new BigDecimal(fen); BigDecimal yuanAmt = fenAmt.divide(new BigDecimal(100)).setScale(2, RoundingMode.DOWN).stripTrailingZeros(); return yuanAmt.toString(); }
测试:
如果不论小数点后面数字为多少,都保留两位的话则吧.stripTrailingZeros()方法去掉
public static String convertFen2Yuan(String fen) { BigDecimal fenAmt = new BigDecimal(fen); BigDecimal yuanAmt = fenAmt.divide(new BigDecimal(100)).setScale(2, RoundingMode.DOWN); return yuanAmt.toString(); }
测试:
如果转字符串的话,加.toPlainString()就行,比如
new BigDecimal("95.000").stripTrailingZeros().toPlainString()