BigDecimal to string

后端 未结 8 1775
感情败类
感情败类 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:42

    // Convert BigDecimal number To String by using below method //
    
    public static String RemoveTrailingZeros(BigDecimal tempDecimal)
    {
        tempDecimal = tempDecimal.stripTrailingZeros();
        String tempString = tempDecimal.toPlainString();
        return tempString;
    }
    

    // Recall RemoveTrailingZeros
    BigDecimal output = new BigDecimal(0);
    String str = RemoveTrailingZeros(output);
    

提交回复
热议问题