Java.math.BigDecimal.max() Method


Advertisements


Description

The java.math.BigDecimal.max(BigDecimal val)returns the maximum of this BigDecimal and val.

Declaration

Following is the declaration for java.math.BigDecimal.max() method.

public BigDecimal max(BigDecimal val)

Parameters

val − value with which the maximum is to be computed.

Return Value

This method returns the BigDecimal whose value is the greater of this BigDecimal and val. If they are equal, as defined by the compareTo method, this is returned.

Exception

NA

Example

The following example shows the usage of math.BigDecimal.max() method.

package com.tutorialspoint;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

      // create 3 BigDecimal objects
      BigDecimal bg1, bg2, bg3;

      bg1 = new BigDecimal("235");
      bg2 = new BigDecimal("236");

      // assign the max value of bg1, bg2 to bg3
      bg3 = bg1.max(bg2);

      String str = "Maximum Value among " + bg1 + " and "+ bg2+" is "+ bg3;

      // print the maximum value
      System.out.println( str );
   }
}

Let us compile and run the above program, this will produce the following result −

Maximum Value among 235 and 236 is 236

java_math_bigdecimal.htm

Advertisements