Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Name the statement that used to compare two float variable

+3 votes
asked Feb 12 by asish sarkar (350 points)

2 Answers

0 votes
answered Feb 12 by HOTSHOT (140 points)

Comparing floating-point values by using either the equality (==) or inequality (!=) operators is not always accurate because of rounding errors.

Compare the two float values to see if they are close in value.

float a;
float b;

0 votes
answered Feb 13 by Peter Minarik (69,270 points)

The equals (==) operator can do that for you.

In C, you'd have the following code:

#include <stdio.h>

int main()
    float f1 = 3.14f;
    float f2 = 3.0f;
    if (f1 == f2)
        printf("The two floats are equal.");
        printf("The two floats are different.");
    return 0;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.