Java.lang.Number.floatValue() Method
Advertisements
Description
The java.lang.Number.floatValue() method returns the value of the specified number as a float. This may involve rounding or truncation.
Declaration
Following is the declaration for java.lang.Number.floatValue() method
public abstract float floatValue()
Parameters
NA
Return Value
This method returns the numeric value represented by this object after conversion to type float.
Exception
NA
Example
The following example shows the usage of lang.Number.floatValue() method.
package com.tutorialspoint; public class NumberDemo { public static void main(String[] args) { // get a number as integer Integer x = new Integer(123456); // get a number as double Double y = new Double(9876); // print their value as float System.out.println("x as integer:" + x + ", x as float:" + x.floatValue()); System.out.println("y as double:" + y + ", y as float:" + y.floatValue()); } }
Let us compile and run the above program, this will produce the following result −
x as integer:123456, x as float:123456.0 y as double:9876.0, y as float:9876.0
java_lang_number.htm
Advertisements