J
J
Jonh Doe2014-01-27 22:27:13
C++ / C#
Jonh Doe, 2014-01-27 22:27:13

Float in C, is 0.41 really 0.40999?

int main(void) {
    float x = 0.41;
    printf("%.50f",x);
}

and see
0.40999999642372131347656250000000000000000000000000

I can't understand why. Any experts on C? Tell pliz.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ocelot, 2014-01-28
@CodeByZen

0.41 cannot be exactly represented as a sum of binary digits N1*(1/2)+N2*(1/4)+N3*(1/8)+... Only with some limited precision. Just as the number 1/3 cannot be represented as a finite decimal fraction.

T
tsarevfs, 2014-01-27
@tsarevfs

The number is stored in binary form. Read the wiki to get started.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question