View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
How to printf float data as a special format? |
Posted: Tue Feb 08, 2005 5:09 pm |
|
|
I have a string like str=" 267.8765 ";
I want to output them as something like "267.88'
I used f=atof(str);
but I do not know how to print out them correctly
any help please? |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Tue Feb 08, 2005 5:25 pm |
|
|
I found out, It is printf("%6.2f",data);
I had something wrong in atof(); I do not know why
str=" 267.8765 ";
f=atof(str);
f just return 0.000000;
any advice? |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Tue Feb 08, 2005 5:33 pm |
|
|
It was not the fault of atof(str); it is the string itself. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Tue Feb 08, 2005 5:36 pm |
|
|
in the string I have some space like this " 236.75674", it was the space that causing the error. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Tue Feb 08, 2005 6:07 pm |
|
|
The question is now becomes how to convert " 352.7356" into "352.7356", please gave some advice. so far this is the big problem, before I try to avoid it, but there is not by pass after I struggled a while. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
Maybe... |
Posted: Tue Feb 08, 2005 9:04 pm |
|
|
Hint:
One way to clean up the string is to try something like this...
for(i=1;i<strlen(str);i++)
if (isamoung(str[i],'1234xxxx.')) valid_num+=str[i]; |
|
|
|