Java Math BigDecimal.stripTrailingZeros() 方法


Java Math BigDecimal.stripTrailingZeros() 方法

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 4 BigDecimal objects

      BigDecimal bg1, bg2, bg3, bg4;



      bg1 = new BigDecimal("235.000");

      bg2 = new BigDecimal("23500");



      // assign the result of stripTrailingZeros method to bg3, bg4

      bg3 = bg1.stripTrailingZeros();

      bg4 = bg2.stripTrailingZeros();



      String str1 = bg1 + " after removing trailing zeros " +bg3;

      String str2 = bg2 + " after removing trailing zeros " +bg4;



      // print bg3, bg4 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}