View previous topic :: View next topic |
Author |
Message |
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
Adding a zero in front of numbers and removing decimal place |
Posted: Tue Aug 26, 2008 1:57 pm |
|
|
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
|
|
Posted: Tue Aug 26, 2008 2:30 pm |
|
|
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
|
|
Posted: Tue Aug 26, 2008 2:38 pm |
|
|
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
|
|
Posted: Tue Aug 26, 2008 3:35 pm |
|
|
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 |
|
|
|