Float shortValue() method in Java with examples
Last Updated :
08 Feb, 2022
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
class GFG {
public static void main(String[] args)
{
Float a = 17 .47f;
Float b = new Float(a);
short output = b.shortValue();
System.out.println("Short value of "
+ b + " is : " + output);
}
}
|
Output:
Short value of 17.47 is : 17
Program 2:
Java
class GFG {
public static void main(String[] args)
{
String value = " 54 .1f";
Float b = new Float(value);
short output = b.shortValue();
System.out.println("Short value of "
+ b + " is : " + output);
}
}
|
Output:
Short value of 54.1 is : 54
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#shortValue()
Share your thoughts in the comments
Please Login to comment...