วันเสาร์ที่ 2 สิงหาคม พ.ศ. 2557

Java java.math MathContext toString()

Description Of MathContext: toString()

The java.math.MathContext.toString() returns the string representation of this MathContext.

The String returned represents the settings of the MathContext object as two space-delimited words (separated by a single space character, '\u0020', and with no leading or trailing white space), as follows:

1. The string "precision=", immediately followed by the value of the precision setting as a numeric string as if generated by the Integer.toString method.

2. The string "roundingMode=", immediately followed by the value of the roundingMode setting as a word. This word will be the same as the name of the corresponding public constant in the RoundingMode enum.

Additional words may be appended to the result of toString in the future if more properties are added to this class.

MathContext.toString() method returns a String representing the context settings.

Code Example Java MathContext

import java.math.MathContext;
import java.math.RoundingMode;

public class BigDecimalExam {
 public static void main(String[] args) {
  MathContext mc1 = new MathContext(2, RoundingMode.DOWN);
  MathContext mc2 = new MathContext(2, RoundingMode.HALF_UP);

  String i1 = mc1.toString();
  String i2 = mc2.toString();

  // print i1, i2 values
  System.out.println(i1);
  System.out.println(i2);
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น