MathContext getPrecision() Method in Java
Last Updated :
20 Jun, 2018
The java.math.MathContext.getPrecision() is an in-built function in Java which returns the precision settings of the MathContext object. This value is always non-negative.
Syntax :
public int getPrecision()
Parameters: The method does not take any parameters.
Return Value: This method returns an int which is the value of the precision setting of the MathContext object.
Examples:
Input : m1 = new MathContext(7);
Output : 7
Input : m1 = new MathContext(2, RoundingMode.HALF_UP);
Output : 2
Below programs illustrate the use of getPrecision() function :
Program 1 :
import java.math.*;
import java.io.*;
class GFG {
public static void main(String[] args)
{
MathContext m1;
m1 = new MathContext( 2 , RoundingMode.HALF_UP);
System.out.println(m1.getPrecision());
}
}
|
Program 2 :
import java.math.*;
import java.io.*;
class GFG {
public static void main(String[] args)
{
MathContext m1;
m1 = new MathContext( 50 );
System.out.println(m1.getPrecision());
}
}
|
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/MathContext.html#getPrecision()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...