Java Number.floatValue()

Syntax

Number.floatValue() has the following syntax.

public abstract float floatValue()

Example

In the following code shows how to use Number.floatValue() method.


/* w  ww .  ja v  a 2 s.  c  o  m*/

public class Main {

   public static void main(String[] args) {

      // get a number as integer
      Number x = new Integer(123456);

      // get a number as double
      Number 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());

   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable