String to double function in Borland C is giving me some headaches.
I have a text string txt[] confirmed as "16.90"
double blah;
blah = strtod(txt,&endptr);
display blah = 16.90, all OK
blah = (blah * 100);
display blah = 1690, all OK, that's an integer.
signed long x;
x = blah;
display x = 1689 (what the???)
More testing shows this rounding down fault happens on many numbers... Positive and negative. I assume it's from the compiler assigning x = blah. I tried the usual typecasting kludges etc to no avail.
Can anyone suggest an accurate way to extract a number with decimal point from a string that WON'T fail? I'm not going to trust double or strtod() any further...
I have a text string txt[] confirmed as "16.90"
double blah;
blah = strtod(txt,&endptr);
display blah = 16.90, all OK
blah = (blah * 100);
display blah = 1690, all OK, that's an integer.
signed long x;
x = blah;
display x = 1689 (what the???)
More testing shows this rounding down fault happens on many numbers... Positive and negative. I assume it's from the compiler assigning x = blah. I tried the usual typecasting kludges etc to no avail.
Can anyone suggest an accurate way to extract a number with decimal point from a string that WON'T fail? I'm not going to trust double or strtod() any further...