Java Math MathContext.toString() 方法


Java Math MathContext.toString() 方法

package com.codingdict;



import java.math.*;



public class MathContextDemo {



   public static void main(String[] args) {



      // create 2 MathContext objects

      MathContext mc1, mc2;



      // assign context settings to mc1, mc2

      mc1 = new MathContext(6, RoundingMode.DOWN);

      mc2 = new MathContext(20, RoundingMode.FLOOR);



      // create 2 String objects

      String s1, s2;



      // assign string representation of mc1, mc2 to s1, s2

      s1 = mc1.toString();

      s2 = mc2.toString();



      String str1 = "String representation of mc1 is " + s1;

      String str2 = "String representation of mc2 is " + s2;



      // print s1, s2 values

      System.out.println( str1 );

      System.out.println( str2 );

   }

}