VOOZH about

URL: https://www.geeksforgeeks.org/java/bigdecimal-round-method-in-java/

⇱ BigDecimal round() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigDecimal round() Method in Java

Last Updated : 4 Dec, 2018
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. Syntax:
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: Program 1:
Output:
The value of 4.2585 after rounding is 4.259
Program 2:
Output:
The value of -4.2585 after rounding is -4.259
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#round(java.math.MathContext)
Comment