Shop OBEX P1 Docs P2 Docs Learn Events
String Conversion — Parallax Forums

String Conversion

SandaltanSandaltan Posts: 5
edited 2006-08-20 17:39 in BASIC Stamp
I am using SERIN to recieve a number from 1 to 999 (1 to 3 numbers long) following a "G" and ending with a "."

The string command:

SERIN 0, N4800, 3000, TimedOut,[noparse][[/noparse]WAIT ("G,"), STR Number\3\"."]

works great because I am not sure how long the number is.

Unfortunately, I get a string of numbers when I am finished. The PBasic manual makes reference to this:

"Without the decimal formatter, however, you would have been forced to receive each character ("1", "2" and "3") separately, and then would still have to do some manual conversion to arrive at the number 123 (one hundred twenty three) before you can do the desired calculations on it."

So I didn't use the decimal formatter DEC because I didn't know the length of the number. So is this "manual conversion" difficult to do? or is there another way?

thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-20 16:43
    You can still use the decimal formatter as in:
    SERIN 0,N4800,3000,TimedOut[noparse][[/noparse]WAIT("G,"),DEC Number]
    The SERIN will use the decimal point as a terminating character for the number, and then discard it.
    If you don't put a digit count after the DEC, PBasic accepts any length by using a non-digit terminating character.
    There is a table of examples in the back of the PBasic Manual in one of the appendices.
  • SandaltanSandaltan Posts: 5
    edited 2006-08-20 17:39
    Wow! super helpful. I really appreciate it.
Sign In or Register to comment.