BigDecimal with smart precision (scale) [duplicate]
问题 This question already has answers here : Removing trailing zeros from BigDecimal in Java (6 answers) Closed 2 years ago . How to set generic scaling according to decimal roundness as a number BigDecimal num = new BigDecimal(25) BigDecimal result = num.divide(new BigDecimal(13), 7, RoundingMode.HALF_EVEN) // 1.9230769 but BigDecimal result = num.divide(new BigDecimal(10), 7, RoundingMode.HALF_EVEN) // 2.5000000 that should be 2.5 Probably analyzing remainder? Is there something in the API for