VOOZH about

URL: https://www.geeksforgeeks.org/java/bigdecimal-shortvalueexact-method-in-java/

⇱ BigDecimal shortValueExact() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigDecimal shortValueExact() Method in Java

Last Updated : 4 Dec, 2018
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:
Output:
Exact short value of 457 is 457
Exact short value of 4785 is 4785
Program 2:
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