See the Tutorial List

Float Class


Below are the Methods of Float class and their example.

1. toString()

Syntax:

	
public String toString(float b)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F; 
System.out.println("toString(a) = " + Float.toString(a)); 
	}
}
	

float-class


2. valueOf()

Syntax

	
public static Float valueOf(float b)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	String b = "63"; 
	Float x = Float.valueOf(a); 
System.out.println("valueOf(a) = " + x); 
        x = Float.valueOf(b); 
System.out.println("ValueOf(b) = " + x);         
	}
}
	

float-class-example


3. parseFloat()

Syntax:

	
public static float parseFloat(String val)
             throws NumberFormatException
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	String b = "63"; 
	float x = Float.parseFloat(b); 
System.out.println("parseFloat(b) = " + x);        
	}
}
	

float-class-example


4. byteValue()

Syntax

	
public byte byteValue()
	

5. shortValue()

Syntax

	
public short shortValue()
	

6. intValue()

Syntax

	
public int intValue()
	

7. longValue()

Syntax

	
public long longValue()
	

8. doubleValue()

Syntax

	
public double doubleValue()
	

9. floatValue()

Syntax:

	
public float floatValue()
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	System.out.println("bytevalue(obj) = " + obj.byteValue()); 
System.out.println("shortvalue(obj) = " + obj.shortValue()); 
System.out.println("intvalue(obj) = " + obj.intValue()); 
System.out.println("longvalue(obj) = " + obj.longValue()); 
System.out.println("doublevalue(obj) = " + obj.doubleValue()); 
System.out.println("floatvalue(obj) = " + obj.floatValue()); 

	}
}
	

float-class-example-2.JPG


10. hashCode()

Syntax:

	
public inthashCode()
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	int x = obj.hashCode(); 
System.out.println("hashcode(x) = " + x); 
	}
}
	

float-class-example


11. isNaN()

Syntax:

	
public booleanisNaN()
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	Float x = Float.valueOf(a); 
System.out.println("isNaN(d) = " + x.isNaN());  
	}
}
	

float-class-example


12. isInfinite()

Syntax:

	
public booleanisInfinite()
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	Float x = Float.valueOf(a); 
	x = Float.valueOf(Float.POSITIVE_INFINITY + 1); 
System.out.println("Float.isInfinite(x) = " + Float.isInfinite(x.floatValue()));
	}
}
	

float-class-example


13. toHexString()

Syntax:

	
public static String toHexString(float val)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	System.out.println("Float.toString(a) = " + Float.toHexString(a));	
	}
}
	

float-class-example


14. floatToIntBits()

Syntax:

	
public static intfloatToIntBits(float val)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	int x = Float.floatToIntBits(a); 
System.out.println("Float.floatToLongBits(a) = " + x); 
	}
}
	

float-class-example


15. floatToRawIntBits()

Syntax:

	
public static intfloatToRawIntBits(float val)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
        float a = 72.05F;
	Float obj = new Float(a); 
	int x = Float.floatToRawIntBits(a); 
System.out.println("Float.floatToRawIntBits(a) = " + x); 
	}
}
	

float-class-example


16. IntBitsToFloat()

Syntax:

	
public static float IntBitsToFloat(long b)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
int a = 72;
float y = Float.intBitsToFloat(a); 
System.out.println("Float.intBitsToFloat(a) = " + y); 
	}
}
	

float-class-example


17. equals()

Syntax:

	
public boolean equals(Object obj)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
	float a = 25.34F;
	String b = "26";
        Float obj = new Float(a); 
        Float obj1 = new Float(b); 
	boolean x = obj.equals(obj1); 
System.out.println("obj.equals(obj1) = " + x);
	}
}
	

float-class-example


18. compareTo()

Syntax:

	
public intcompareTo(Float b)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
	float a = 25.34F;
	String b = "26";
        Float obj = new Float(a); 
        Float obj1 = new Float(b); 
	int x = obj.compareTo(obj1); 
System.out.println("obj.compareTo(obj1) = " + x);
	}
}
	

float-class-example


19. compare()

Syntax:

	
public static int compare(float x,float y)
	

Example:

	
public class FloatDemo1
{ 
    public static void main(String[] args)  
	{ 
	float a = 25.34F;
	String b = "26";
        Float obj = new Float(a); 
        Float obj1 = new Float(b); 
	int x = Float.compare(obj, obj1); 
System.out.println("compare(obj, obj1) = " + x);
	}
}
	

float-class-example