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 convert Floating point into Ascii

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








How to convert Floating point into Ascii
PostPosted: Fri Aug 19, 2005 9:34 am     Reply with quote

Hello, i need some help please.

I have a float variable such as "result". Lets say that result is the number 9.804. Then i would like to generate an arrange of elements in ascii as the following:

text[0]="9"
text[1]="."
text[2]="8"
text[3]="0"
text[4]="4"

So text[]="9.804"

How can I do that? is there any function in CCS compiler for this purpose?
I would appreciatte any help on this matter.

Thanks!
Ttelmah
Guest







PostPosted: Fri Aug 19, 2005 9:46 am     Reply with quote

Code:

sprintf(text,"%5.3f",result);


Remember though that 'text' will need to be big enough to contain the string terminator as well (another character), and is safer made a little larger.

Best Wishes
alefarre



Joined: 17 Jun 2005
Posts: 3

View user's profile Send private message

Ascii
PostPosted: Fri Aug 19, 2005 11:41 am     Reply with quote

Thanks. It works!
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