有些财务业务场景是需要把数字多余的0去掉的。

可以这么写

private String getRealData(BigDecimal num) {
if (num == null) {
return "0";
}
String value = num.stripTrailingZeros().toString();
return value;
}

 

也可以这么写

private String getRealData(BigDecimal num) {
if (num == null) {
return "0";
}
String value = new BigDecimal(num.doubleValue()).toString();
String[] temp = value.split("\\.");
if (temp[1].equals("0")) {
return temp[0];
}
return value;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案