BigDecimal.shortValueExact() has the following syntax.
public short shortValueExact()
In the following code shows how to use BigDecimal.shortValueExact() method.
// ww w . ja va2s . 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.