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 support@ccsinfo.com

Adding a zero in front of numbers and removing decimal place

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



Joined: 06 Sep 2006
Posts: 12

View user's profile Send private message

Adding a zero in front of numbers and removing decimal place
PostPosted: Tue Aug 26, 2008 1:57 pm     Reply with quote

Folks,

I am trying to take a known variable that is in the format "xx.xx" and do two things to it. The number range is from 7.00 to 24.99. I would like to add a zero to the begining and remove the decimal. Example: 3.66 would then be 0366 or 12.72 would be 1272. I have a feeling I am missing something so obvious that is right in my face. My goal is to take 2 variables and put them together in a string and send it out the serial port.

Any help would be greatly appreciated.

Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 2:30 pm     Reply with quote

You can use sprintf to make a float into an ascii string. The output of
sprintf is put into a output buffer. You must declare the char array for
the output buffer before you use sprintf. Then you can edit the array
(with code designed by you) and do whatever you want with it.
After editing, you can transmit the string in the array through the serial port.
Ttelmah
Guest







PostPosted: Tue Aug 26, 2008 2:38 pm     Reply with quote

Or what about just multiplying the number by 100, storing the result in an integer (long), and using printf, with (say) %04ld.

Best Wishes
Steve_Kos



Joined: 06 Sep 2006
Posts: 12

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 3:35 pm     Reply with quote

PCM Programmer: Thank you for the advice, I will keep that in mind.

Ttelmah: Thanks, it worked like a champ. So simple, I knew it was staring me in the face.


Thanks!
Steve
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