This is the code

char number[]="0.58";
double value = atof(number);

When I execute it value is 0.57999999999999996

Do you know why?

Thanks in advance

your are right and there is nothing you can do about it because of the way floats and doubles are stored in memory. wikipedia has a good article about that

"0.58" ... atof ... 0.57999999999999996
Do you know why?

The decimal system is not the dual system.
Try to express 0.58 as a quotient of two integer numbers with the denominator being a power of two!

(58/100 = 29/50 = 29 / (5*5*2) -> Is there a way to multiply this by a power of two to get an integer number?)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.