+ 2
Why is 1.1 not getting printed here? Please tell me!
6 Respuestas
+ 3
Most floating point numbers don't have exact binary representation, so they should not be compared directly.
in line 6, you should write:
while(x==(float)1.1)
EDIT:
Check the link: https://stackoverflow.com/questions/8266878/why-floating-point-value-conditions-failed-in-if-condition
+ 2
And what should I search in Search engines to get further details about conversions like (float)1.1.
implicit conversion or what is it called?..
I've just begun,so don't know much of the terminology
+ 1
Beacause of the memory representation of float variables.
1.1 is represented as 1.0999999 in memory as binary numbers. @blue has suggested the correct possible solution to the problem.
+ 1
I just tried what Blue has suggested and got this error.
Error: Expected expression before float.
+ 1
It worked fine on my device. Don't forget the parentheses () on float
+ 1
These conversions are called explicit conversion meaning forceful conversion of data types.