Click to See Complete Forum and Search --> : atof is not exact


wakeup
April 2nd, 2008, 04:12 AM
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

laitinen
April 2nd, 2008, 04:20 AM
Do you know why?Yes I do.

If you want to know, please read these: How is floating point representated? (http://www.codeguru.com/forum/showthread.php?t=323835) and What are different number representations? (http://www.codeguru.com/forum/showthread.php?t=316299)

Laitinen

MrViggy
April 2nd, 2008, 04:19 PM
Yep. It has nothing to do with 'atof' but how floating point numbers are represented in a binary machine.

Viggy