VOOZH about

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

⇱ BigDecimal max() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigDecimal max() Method in Java

Last Updated : 4 Dec, 2018
The java.math.BigDecimal.max(BigDecimal val) method in Java is used to compare two BigDecimal values and return the maximum of the two. This is opposite to BigDecimal max() method in Java. Syntax:
public BigDecimal max(BigDecimal val)
Parameters: The function accepts a BigDecimal object val as parameter whose value is compared with that of this BigDecimal object and the maximum value is returned. Return Values: This method returns the BigDecimal whose value is the greater of this BigDecimal and val. In case if both are equal, this BigDecimal is returned. Examples:
Input : a = 17.000041900, b = 17.0000418999
Output : 17.000041900

Input : a = 235900000146, b = 236000000000
Output : 236000000000
Below programs will illustrate max() function of BigDecimal class. Program 1:
Output:
Maximum Value among 235900000146 and 236000000000 is 236000000000
Program 2:
Output:
Length of string GeeksforGeeks is 13
Length of string GeeksClasses is 12
Maximum length is 13
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#max()
Comment