java.lang.Double floatValue()

Syntax:

public float floatValue()

Java Code Example :

This java example source code demonstrates the use of floatValue() method of Double class.

Some takeaways on the longValue()  method:

  • returns the value of this Double as a float after a narrowing primitive conversion
  • specified by floatValue in class Number
  • since JDK 1.0
package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of  
 * floatValue() method of Double class
 */

public class DoubleFloatValue {

	public static void main(String[] args) {

		
		/*
		 * Both the variable anotherResult and testResult 
		 * will yield to the same value of the loss of precision 
		 * 
		 */

		Double anotherValue = 65.38751;
		float anotherResult = anotherValue.floatValue();
		System.out.println("Double " + anotherValue + " long value="
				+ anotherResult);

		Double testValue = 65.3875132;
		float testResult = testValue.floatValue();
		System.out.println("Double " + testValue + " float value=" 
				+ testResult);

	}

}

Sample Output :

Running the above example source code will give the following output

Double 65.38751 long value=65.38751
Double 65.3875132 float value=65.38751

Suggested Reading List :

References :