# BigDecimal signum() Method in Java

The java.math.BigDecimal.signum() is an inbuilt method in Java that returns the signum function of this BigDecimal. The sign function or signum function is an odd mathematical function that extracts the sign of a real number. In mathematical expressions, the sign function is often represented as sgn.

Syntax:

```public int signum()
```

Parameters: This method does not accepts any parameter.

Return value: This method can return three types of values:

• -1 if this BigDecimal < 0
• 0 if this BigDecimal = 0
• 1 if this BigDecimal is > 0

Below program illustrates the working of the above mentioned method:

Program 1:

 `// Program to demonstrate signum() method of BigDecimal  ` ` `  `import` `java.math.*; ` ` `  `public` `class` `Gfg { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``BigDecimal b1 = ``new` `BigDecimal(``"12743"``); ` `        ``BigDecimal b2 = ``new` `BigDecimal(``"0"``); ` `        ``BigDecimal b3 = ``new` `BigDecimal(``"-4512"``); ` ` `  `        ``// Assigning the signum values of  BigDecimal objects b1, b2, b3 ` `        ``// to  int objects i1, i2, i3 respectively ` `        ``int` `i1 = b1.signum(); ` `        ``int` `i2 = b2.signum(); ` `        ``int` `i3 = b3.signum(); ` ` `  `        ``// Printing i1, i2, i3 values ` `        ``System.out.println(``"Signum function on "` `+ b1 + ``" is "` `+ i1); ` `        ``System.out.println(``"Signum function on "` `+ b2 + ``" is "` `+ i2); ` `        ``System.out.println(``"Signum function on "` `+ b3 + ``" is "` `+ i3); ` `    ``} ` `} `

Output:

```Signum function on 12743 is 1
Signum function on 0 is 0
Signum function on -4512 is -1
```

Program 2:

 `// Program to demonstrate signum() method of BigDecimal  ` ` `  `import` `java.math.*; ` ` `  `public` `class` `Gfg { ` ` `  `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` ` `  `        ``BigDecimal b1 = ``new` `BigDecimal(``"17845452743"``); ` `        ``BigDecimal b2 = ``new` `BigDecimal(``"000"``); ` `        ``BigDecimal b3 = ``new` `BigDecimal(``"-444512"``); ` ` `  `        ``// Assigning the signum values of  BigDecimal objects b1, b2, b3 ` `        ``// to  int objects i1, i2, i3 respectively ` `        ``int` `i1 = b1.signum(); ` `        ``int` `i2 = b2.signum(); ` `        ``int` `i3 = b3.signum(); ` ` `  `        ``// Printing i1, i2, i3 values ` `        ``System.out.println(``"Signum function on "` `+ b1 + ``" is "` `+ i1); ` `        ``System.out.println(``"Signum function on "` `+ b2 + ``" is "` `+ i2); ` `        ``System.out.println(``"Signum function on "` `+ b3 + ``" is "` `+ i3); ` `    ``} ` `} `

Output:

```Signum function on 17845452743 is 1
Signum function on 0 is 0
Signum function on -444512 is -1
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.