Float shortValue() method in Java with examples
The shortValue() method in Float Class is a built-in method in Java which returns the value specified by calling the object as short after typecasting.
Syntax:
public short shortValue()
Return Value: It return the value of FloatObject as short.
Below programs illustrate shortValue() method in Java:
Program 1:
// Java code to demonstrate // Float shortValue() method class GFG { public static void main(String[] args) { // Float value Float a = 17.47f; // wrapping the Float value // in the wrapper class Float Float b = new Float(a); // shortValue of the Float Object short output = b.shortValue(); // prshorting the output System.out.println("Short value of " + b + " is : " + output); } } |
chevron_right
filter_none
Output:
Short value of 17.47 is : 17
Program 2:
// Java code to demonstrate // Float shortValue() method class GFG { public static void main(String[] args) { String value = "54.1f"; // wrapping the Float value // in the wrapper class Float Float b = new Float(value); // shortValue of the Float Object short output = b.shortValue(); // prshorting the output System.out.println("Short value of " + b + " is : " + output); } } |
chevron_right
filter_none
Output:
Short value of 54.1 is : 54
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#shortValue()
Recommended Posts:
- Number.shortValue() method in java with examples
- Byte shortValue() method in Java with examples
- Double shortValue() method in Java with examples
- Java Guava | Floats.indexOf(float[] array, float target) method with Examples
- Java Guava | Floats.indexOf(float[] array, float[] target) method with Examples
- Short shortValue() Method in Java
- Integer shortValue() Method in Java
- Float hashCode() method in Java with examples
- Float floatToRawIntBits() method in Java with examples
- Float equals() method in Java with examples
- Float floatToIntBits() method in Java with examples
- Float doubleValue() method in Java with examples
- Float parseFloat() method in Java with examples
- Float byteValue() method in Java with Examples
- Float isInfinite() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



