BigDecimal shortValueExact() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.math.BigDecimal.shortValueExact() is an inbuilt method in java that converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown. Syntax: public short shortValueExact() Parameters: The method does not accepts any parameter. Return value: This method returns the short value of the BigDecimal Object. Below programs illustrates the above mentioned method: Program 1: Java // Program to demonstrate shortValueExact() method of BigDecimal import java.math.*; public class gfg { public static void main(String[] args) { BigDecimal b1 = new BigDecimal("457"); BigDecimal b2 = new BigDecimal("4785"); // Assigning the short value of BigDecimal objects b1 and b2 // to short s1, s2 respectively short s1 = b1.shortValueExact(); short s2 = b2.shortValueExact(); // Printing s1, s2 values System.out.println("Exact short value of " + b1 + " is " + s1); System.out.println("Exact short value of " + b2 + " is " + s2); } } Output: Exact short value of 457 is 457 Exact short value of 4785 is 4785 Program 2: Java // Program to demonstrate shortValueExact() method of BigDecimal import java.math.*; public class gfg { public static void main(String[] args) { BigDecimal b1 = new BigDecimal("127"); BigDecimal b2 = new BigDecimal("1455"); // assign the short value of BigDecimal objects b1 and b2 // to short s1, s2 respectively short s1 = b1.shortValueExact(); short s2 = b2.shortValueExact(); // print s1, s2 values System.out.println("Exact short value of " + b1 + " is " + s1); System.out.println("Exact short value of " + b2 + " is " + s2); } } Output: Exact short value of 127 is 127 Exact short value of 1455 is 1455 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#shortValueExact() Comment More infoAdvertise with us Next Article BigDecimal toBigIntegerExact() Method in Java T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-Functions java-math Java-BigDecimal Java-math-package +2 More Practice Tags : JavaMisc Similar Reads BigDecimal valueOf() Method in Java java.math.BigDecimal.valueOf(long val) is an inbuilt method in Java that translates a long value into a BigDecimal value with a scale of zero. It allows us, the reuse of frequently used BigDecimal values and hence this "static factory method" is provided in preference to a (long) constructor. Packag 3 min read BigDecimal toBigIntegerExact() Method in Java The java.math.BigDecimal.toBigIntegerExact() is an inbuilt method in java that converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part. Syntax: public BigInteger toBigIntegerExact() Parameters: The method does n 2 min read BigDecimal toBigIntegerExact() Method in Java The java.math.BigDecimal.toBigIntegerExact() is an inbuilt method in java that converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part. Syntax: public BigInteger toBigIntegerExact() Parameters: The method does n 2 min read BigDecimal plus() method in Java The java.math.BigDecimal.plus() is an inbuilt method in java that returns a BigDecimal whose value is (+this), and whose scale is this.scale(). This method, which simply returns this BigDecimal is included for symmetry with the unary minus method negate().Syntax: public BigDecimal plus()Parameters: 3 min read BigDecimal toBigInteger() Method in Java The java.math.BigDecimal.toBigInteger() is an inbuilt method in java that converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long. Any fractional part of this BigDecimal will be discarded. This conversion can lose information a 2 min read BigDecimal stripTrailingZeros() Method in Java The java.math.BigDecimal.stripTrailingZeros() is an inbuilt method in Java that returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. So basically the function trims off the trailing zero from the BigDecimal value. Syntax: public Big 2 min read Like