Java BigDecimal.shortValueExact()

Syntax

BigDecimal.shortValueExact() has the following syntax.

public short shortValueExact()

Example

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


/*from  w  w  w.  j  av  a 2s .  c  o  m*/
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

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

    // assign the short value of bg1 and bg2 to s1,s2 respectively
    short s1 = bg1.shortValueExact();
    short s2 = bg2.shortValueExact();

    String str1 = "Exact short value of " + bg1 + " is " + s1;
    String str2 = "Exact short value of " + bg2 + " is " + s2;

    // print s1,s2 values
    System.out.println(str1);
    System.out.println(str2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger