15,745,973 members
See more:
My doubt is :
we write
`float a = 25.33f;`

which is of course a normal way of initializing a float variable...

now we can also do the same thing in this way
`float a = 25.33;`

now my doubt is whether their is a difference between the above two statements as far as i know both are going to perform the same thing but in the first statement their is 'f' written at the end of 25.33 so what does that 'f' indicate i know it indicates that the data stored will be of floating type but the second statement also means the same so why do we write 'f' at the end of any float number

i tried this piece of code
```void main()
{
float a= 0.7;
if (a < 0.7)
printf("c");
else
printf("c++");
} ```

Output of the above program is c. Why? so
i googled it i found that 0.7 is a constant and the float 0.7 is rounded to 0.699999988 how it is rounded to 0.699999988 and in case of 0.8
a=0.800000011 and
constant 0.8 is 0.8000000000000000 whats the actual logic behind that, please if anyone can help me out i would be thankful

Thanks & Regards
Posted

## Solution 2

floating point numbers on computers can represent numbers exactly that are sums of powers of two. You can get close to an arbitrary decimal number with so many binary bits but you might not be able to get it exactly.

So, if we're aiming to represent 0.7 in decimal in binary:

0.1 (where the . is the binary point) => 1 / 2 decimal => 0.5
0.11 => 3 / 4 decimal => 0.75
0.101 => 5 / 8 decimal => 0.625
0.1011 => 11 / 16 decimal => 0.6875
0.10111 => 23 / 32 decimal => 0.71875
0.101101 => 45 / 64 decimal => 0.703125

...

0.1011001101 => 717 / 1024 decimal => 0.7001953125 (10 bit encoding)

ad nauseaum until you run out of bits. Each 3 or 4 extra bits might give you another decimal point of accuracy so by the time you get to 20 or so bits you've only got 7 or so digits of accuracy.

(someone better at maths might like to prove it, I can't! :-) )

Cheers,

Ash

v2
john_th 25-Jul-13 10:02am

## Solution 1

float a = 25.33;

This implicitly converts the double to a float.

Output of the above program is c. Why?

Floating point numbers in C are not precise. Float is less precise than double.