BigDecimal round() Method in Java
The java.math.BigDecimal.round(MathContext m) is an inbuilt method in Java that returns a BigDecimal value rounded according to the MathContext settings. If the precision setting is 0 then no rounding takes place.
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.
public BigDecimal round(MathContext m)
Parameters: The method accepts a single parameter m which refers to the context to use that is the value up to which the BigDecimal value is to be rounded off.
Return value: This method returns a BigDecimal rounded according to the MathContext settings.
Below programs illustrate the working of java.math.BigDecimal.round(MathContext m) method:
The value of 4.2585 after rounding is 4.259
The value of -4.2585 after rounding is -4.259