CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to printf float data as a special format?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

How to printf float data as a special format?
PostPosted: Tue Feb 08, 2005 5:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 5:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 5:33 pm     Reply with quote

It was not the fault of atof(str); it is the string itself.
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 5:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 6:07 pm     Reply with quote

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

View user's profile Send private message

Maybe...
PostPosted: Tue Feb 08, 2005 9:04 pm     Reply with quote

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];
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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