Java.lang.Float.shortValue() Method

Advertisements


Description

The java.lang.Float.shortValue() method returns the value of this Float as a short (by casting to a short).

Declaration

Following is the declaration for java.lang.Float.shortValue() method

public short shortValue()

Parameters

  • NA

Return Value

This method returns the float value represented by this object converted to type short.

Exception

  • NA

Example

The following example shows the usage of java.lang.Float.shortValue() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

     /* returns the float value represented by this object
     converted to type short */
     Float obj = new Float("6.52");
     short s = obj.shortValue();
     System.out.println("Value = " + s);
    
     obj = new Float("5");
     s = obj.shortValue();
     System.out.println("Value = " + s);
   }
}   

Let us compile and run the above program, this will produce the following result:

Value = 6
Value = 5



Advertisements
Advertisements