The java.math.MathContext.toString() function is an in-built function in Java which returns the string representation of a MathContext object’s context settings.
The string returned represents the settings of the MathContext object as two space-separated words. These two space-separated strings are as follows :
- The first part of the returned string displays the value of the precision settings preceded by string “precision=”
- The second part of the returned string displays the value of the RoundingMode settings preceded by string “roundingMode=”
public String toString()
Parameter: The method accepts no parameter.
Return Values: This method returns a string representing the context settings of the object of the MathContext class in the format mentioned above.
Input : m1 = new MathContext(2, RoundingMode.HALF_DOWN) Output : precision=2 roundingMode=HALF_DOWN Input : m1 = new MathContext(60) Output : precision=60 roundingMode=HALF_UP
Below programs illustrates the use of java.math.MathContext.toString() function :
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.