Java Math BigDecimal.round() 方法


Java Math BigDecimal.round() 方法

package com.codingdict;



import java.math.*;



public class BigDecimalDemo {



   public static void main(String[] args) {



      // create 2 BigDecimal Objects

      BigDecimal bg1, bg2;



      bg1 = new BigDecimal("5.46497");



      MathContext mc = new MathContext(3); // 3 precision



      // bg1 is rounded using mc

      bg2 = bg1.round(mc);



      String str = "The value " + bg1 + " after rounding is " + bg2;



      // print bg2 value

      System.out.println( str );

   }

}