Shop OBEX P1 Docs P2 Docs Learn Events
int to string — Parallax Forums

int to string

hkimballhkimball Posts: 15
edited 2007-05-14 20:59 in Propeller 1
Quick question.

What am I doing wrong here?· When I pass in this negative number, convert to int then back to string i get 53,502.· If I pass in 12034 it comes back 12,304.· Am I missing something in my tostr funtion call?·

tempint := num.FromStr(STRING("-12034"),num#DEC)
tv.str(num.tostr(tempint,num#ddec))

Thanks in advance.

Harold

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-05-11 21:09
    Which object are you using (the num one)?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • hkimballhkimball Posts: 15
    edited 2007-05-11 21:14
    yes numbers, sorry about that
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-05-11 22:46
    Im not getting the results you are, I ran the attached program and the following was displayed:

    -12034
    -12034
    -12,034

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • hkimballhkimball Posts: 15
    edited 2007-05-14 20:06
    sorry i did not get back to your response sooner but i was away from my hardware for a few days.

    i think i figured out what was causing the problem though, thanks to your example

    in your example tempint is a long, in my code tempint was a word, when tempint is a word the results i stated are returned by the conversion

    question??
    if you are using signed integers, the variables passed to the numbers object must be longs???
  • hkimballhkimball Posts: 15
    edited 2007-05-14 20:25
    ok, i answered my own question. i went to the numbers object and looked inside and it is expecting longs.
  • M. K. BorriM. K. Borri Posts: 279
    edited 2007-05-14 20:51
    You have to sign-extend stuff in this case, right?
  • hkimballhkimball Posts: 15
    edited 2007-05-14 20:59
    you are right.
    i just tried it out and i can keep my variable a word as long as i sign-extend the value when i pass it into the tostr function

    thanks for the tip
Sign In or Register to comment.