Java Number - shortValue() Method
The java.lang.Number.shortValue() method returns the value of the specified number as a short, which may involve rounding or truncation. This implementation returns the result of intValue() cast to a short.
Syntax
public short shortValue()
Parameters
No parameter is required.
Return Value
Returns the numeric value represented by this object after conversion to type short.
Exception
NA.
Example:
In the example below, the java.lang.Number.shortValue() method returns the short value of the given numbers.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating an Double value Double val1 = 123.23; //creating a Float value Float val2 = 55.75f; //printing the short value of given numbers System.out.println("short value of val1: " + val1.shortValue()); System.out.println("short value of val2: " + val2.shortValue()); } }
The output of the above code will be:
short value of val1: 123 short value of val2: 55
❮ Java.lang - Number