|
|
View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
problem/limitations with atof()? |
Posted: Sat May 26, 2007 1:35 pm |
|
|
In trying to convert a latitude/longitude set to floating point, I ran across a curious problem with an 18LF252 and an 18LF2525. In a test case, I formatted a string with 4 characters, a decimal point, and 4 more characters. I tried an atof() on the string and got an invalid answer. In checking other posts related to the subject, I found one that showed the only issue was precision, not validity. I tried decreasing values in the string and repeated the atof() test. It seems three digit characters before the decimal point is the limitation. Is this a real limitation? Is there a work-around or alternative solution?
My test result outputs are as follows:
string: 4329.6466 float: 34.679296
string: 329.6466 float: 329.646656
string: 29.6466 float: 29.646602
string: 9.6466 float: 9.646600
string: .6466 float: 0.646600
string: 6466 float: -2123.934719
Is this documented somewhere?
Thanks.
|
|
|
Ttelmah Guest
|
|
Posted: Sat May 26, 2007 2:51 pm |
|
|
atof, is listed in stdlib.h. There is no obvious reason in the listing for a problem. What compiler are you using?. There _is_ a known problem with printf, on the older compilers, if used with '%f', where garbage results are given above a certain size. What is your printf specifier?. Though it is a fault, remember that to display 4.4, requires "%9.4f" (the decimal point is a counted character), and I'd suspect it might be the output that is the problem, rather than atof.
Best Wishes |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
atof() / printf() prpblem |
Posted: Mon May 28, 2007 11:09 am |
|
|
I'm using version 3.249 of the compiler.
You may be right... this may be a printf() problem. I'm using %.4f format (to display 4 digits after the decimal point but allow the front end to expand to fit the number of digits in the value). Is this part of the problem? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|