BigDecimal to string

后端 未结 8 1774
感情败类
感情败类 2020-12-13 08:06

I have a BigDecimal object and i want to convert it to string. The problem is that my value got fraction and i get a huge number (in length) and i only need the original num

8条回答
  •  无人及你
    2020-12-13 08:56

    For better support different locales use this way:

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    df.setGroupingUsed(false);
    
    df.format(bigDecimal);
    

    also you can customize it:

    DecimalFormat df = new DecimalFormat("###,###,###");
    df.format(bigDecimal);
    

提交回复
热议问题