The java.math.BigDecimal.min(BigDecimal val) method in Java is used to compare two BigDecimal values and return the minimum of the two.
Syntax:
public BigDecimal min(BigDecimal val)
Parameters: The function accepts a BigDecimal object val as parameter whose value is compared with that of this BigDecimal object and the minimum value is returned.
Return Values: This method returns the BigDecimal whose value is the smaller 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.0000418999
Input : a = 235900000146, b = 236000000000
Output : 235900000146
Below programs will illustrate min() function of BigDecimal class:
Program 1:
import java.math.*;
public class GFG {
public static void main(String[] args)
{
BigDecimal a, b;
a = new BigDecimal( "17.000041900" );
b = new BigDecimal( "17.0000418999" );
System.out.println( "Minimum Value among " + a +
" and " + b + " is " + a.min(b));
}
}
|
Output:
Minimum Value among 17.000041900 and 17.0000418999 is 17.0000418999
Program 2:
import java.math.*;
public class GFG {
public static void main(String[] args)
{
BigDecimal a, b;
String s = "GeeksforGeeks" ;
String str = "GeeksClasses" ;
int l1, l2;
l1 = s.length();
l2 = str.length();
a = new BigDecimal(l1);
b = new BigDecimal(l2);
System.out.println( "Length of string " + s + " is " + a);
System.out.println( "Length of string " + str + " is " + b);
System.out.println( "Minimum length is " + a.min(b));
}
}
|
Output:
Length of string GeeksforGeeks is 13
Length of string GeeksClasses is 12
Minimum length is 12
Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#min()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
04 Dec, 2018
Like Article
Save Article