Java Math BigDecimal.plus(MathContext mc) 方法


Java Math BigDecimal.plus(MathContext mc) 方法

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("-333.3454");



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



      // perform plus on bg1 using mc

      bg2 = bg1.plus(mc);



      String str = "The Result of plus using context settings is " + bg2;



      // print the value of bg2

      System.out.println( str );

   }

}