# BigDecimal min() Method in Java

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:

 `/*Java program to illustrate ` `use of BigDecimal min()  ` `function in Java      */` `import` `java.math.*; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Creating 2 BigDecimal objects ` `        ``BigDecimal a, b; ` ` `  `        ``a = ``new` `BigDecimal(``"17.000041900"``); ` `        ``b = ``new` `BigDecimal(``"17.0000418999"``); ` ` `  `        ``// print the maximum value ` `        ``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:

 `/*Java program to illustrate ` `use of BigDecimal min()  ` `to display minimum length ` `among two strings  */` `import` `java.math.*; ` ` `  `public` `class` `GFG { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``// Create 2 BigDecimal objects ` `        ``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); ` ` `  `        ``// Print the respective lengths ` `        ``System.out.println(``"Length of string "` `+ s + ``" is "` `+ a); ` `        ``System.out.println(``"Length of string "` `+ str + ``" is "` `+ b); ` `        ``// Print the maximum value ` `        ``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
```

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.