Java BigDecimal.signum()

Syntax

BigDecimal.signum() has the following syntax.

public int signum()

Example

In the following code shows how to use BigDecimal.signum() method.


//from w  w  w  .j a  v  a  2s  . co  m

import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("123");
    BigDecimal bg2 = new BigDecimal("0");
    BigDecimal bg3 = new BigDecimal("-12");

    int i1 = bg1.signum();
    int i2 = bg2.signum();
    int i3 = bg3.signum();

    String str1 = "The Result of Signum function on " + bg1 + " is " + i1;
    String str2 = "The Result of Signum function on " + bg2 + " is " + i2;
    String str3 = "The Result of Signum function on " + bg3 + " is " + i3;

    // print i1,i2,i3 values
    System.out.println(str1);
    System.out.println(str2);
    System.out.println(str3);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger