BigDecimal to string

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

    To archive the necessary result with double constructor you need to round the BigDecimal before convert it to String e.g.

    new java.math.BigDecimal(10.0001).round(new java.math.MathContext(6, java.math.RoundingMode.HALF_UP)).toString()

    will print the "10.0001"

提交回复
热议问题