Java Number floatValue() Method

The floatValue() is a method of Java Number class which returns the float equivalent value of the specified Number object. It may also involve in rounding or truncation of the specified Number value.

Syntax:

Following is the declaration of floatValue() method:

Parameter:

DataTypeParameterDescription
NANAIt does not accept any parameter.

Returns:

The floatValue() method will return the numeric value represented by this object after conversion to type float.

Exceptions:

NA

Compatibility Version:

Java 1.0 and above

Example 1

Test it Now

Output:

Value : 2454.0
Value : 86549.984

Example 2

<

Output:

Enter The Desired Input Value: 123ABCD
Exception in thread "main" java.util.InputMismatchException
	at java.base/java.util.Scanner.throwFor(Scanner.java:939)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
	at myPackage.NumberFloatValueExample2.main(NumberFloatValueExample2.java:9)

Example 3

Test it Now

Output:

Value is = 1.5





Latest Courses