Float compare() Method in Java with Examples Last Updated : 05 Sep, 2023 Comments Improve Suggest changes Like Article Like Report The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(float f1, float f2)Parameters: The function accepts two parameters: f1: The first float value to be compared.f2: The second float value to be compared.Return Value: The function returns value as below: 0: if f1 is numerically equal to f2.Negative value: if f1 is numerically less than f2.Positive value: if f1 is numerically greater than f2.Below programs illustrates the use of Float.compare() function: Program 1: When two integers are same Java // Java Program to illustrate // the Float.compare() method import java.lang.Float; public class GFG { public static void main(String[] args) { // Get the two float values // to be compared Float f1 = 1023f; Float f2 = 1023f; // function call to compare two float values if (Float.compare(f1, f2) == 0) { System.out.println("f1=f2"); } else if (Float.compare(f1, f2) < 0) { System.out.println("f1<f2"); } else { System.out.println("f1>f2"); } } } Outputf1=f2Program 2 : When f1<f2 Java // Java Program to illustrate // the Float.compare() method import java.lang.Float; public class GFG { public static void main(String[] args) { // Get the two float values // to be compared Float f1 = 10f; Float f2 = 1023f; // function call to compare two float values if (Float.compare(f1, f2) == 0) { System.out.println("f1=f2"); } else if (Float.compare(f1, f2) < 0) { System.out.println("f1<f2"); } else { System.out.println("f1>f2"); } } } Outputf1<f2 Program 3 : When f1>f2 Java // Java Program to illustrate // the Float.compare() method import java.lang.Float; public class GFG { public static void main(String[] args) { // Get the two float values // to be compared Float f1 = 1023f; Float f2 = 10f; // function call to compare two float values if (Float.compare(f1, f2) == 0) { System.out.println("f1=f2"); } else if (Float.compare(f1, f2) < 0) { System.out.println("f1<f2"); } else { System.out.println("f1>f2"); } } } Outputf1>f2 Comment More infoAdvertise with us Next Article Float compare() Method in Java with Examples gopaldave Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Float Practice Tags : Java Similar Reads Float compareTo() method in Java with examples The comapreTo() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public int compareTo(Object f) Parameters: The function acce 2 min read Java Guava | Floats.compare() method with Examples Floats.compare() method of Floats Class is used to compare the two specified float values. These values are passed as the parameter and the result of comparison is found as the difference of 1st value and the 2nd value. Hence it can be positive, zero or negative. Syntax: public static int compare(fl 2 min read Float equals() method in Java with examples The equals() method in Float Class is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Float object that contains the same double value as this object. It returns false if both the objects are not same. 3 min read Float doubleValue() method in Java with examples The doubleValue() method of Float class is a built in method to return the value specified by the calling object as double after type casting. Syntax: FloatObject.doubleValue() Return Value: It return the double value of this Float object. Below programs illustrate doubleValue() method in Java: Prog 2 min read Float byteValue() method in Java with Examples The java.lang.Float.byteValue() is a built-in method in Java that returns the value of this Float as a byte(by casting to a byte). Basically it used for narrowing primitive conversion of Float type to a byte value. Syntax: public byte byteValue() Parameters: The function does not accept any paramete 2 min read Like