Shop OBEX P1 Docs P2 Docs Learn Events
integer to string in DAT section — Parallax Forums

integer to string in DAT section

ShawnaShawna Posts: 508
edited 2013-09-30 09:38 in Propeller 1
I would like to take a long variable and convert it into a string.

For instance if I have a value of 989, I would like to store it as a string in the dat section like this.

str byte " 98.9"

Is there an easy way to do this?

I can break the value down into whole numbers and decimals like this
temp := 989
tempDec     := temp // 10
tempWhole := temp / 10


Is there an easy way to do this?

The range is going to be +/- 200.0, so no matter what the value is I need to have 6 characters store in the dat section.


Thanks
Shawn

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-09-28 23:46
    Take a look at the SimpleNumbers object in the Propeller library. IIRC, there's a number-to-string conversion method there.

    -Phil
  • ReachReach Posts: 107
    edited 2013-09-29 20:33
    Temp := 98.9

    Temp would have to be a long but converting it to a few bytes can be done later
    as long as the math is done correctly why not just do like that?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-09-30 09:38
    Temp := 98.9 would result in the following value being stored:

    1120259277 (Decimal)
    42C5CCCD (Hexadecimal)
    01000010110001011100110011001101 (Binary)
Sign In or Register to comment.