Shop OBEX P1 Docs P2 Docs Learn Events
Numbers with Decimal Points — Parallax Forums

Numbers with Decimal Points

ArchiverArchiver Posts: 46,084
edited 2002-11-15 15:07 in General Discussion
Hi All...thanks to all for answering my questions. I have another
question:

My BASIC manual says it cannot handle decimal point entries. I am
writing an application which would need a number with a decimal point
entered from the keyboard and then compared later to an actual
measured value. Anyone have any ideas on how to program this ?

Thanks for all you help...JB

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 16:57
    >Hi All...thanks to all for answering my questions. I have another
    >question:
    >
    >My BASIC manual says it cannot handle decimal point entries. I am
    >writing an application which would need a number with a decimal point
    >entered from the keyboard and then compared later to an actual
    >measured value. Anyone have any ideas on how to program this ?
    >
    >Thanks for all you help...JB

    Lets say you need 2 decimal places. Then in your program, work with
    100* all th e values.
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 17:01
    It depends on exactly what you need to do. If you just need to store the
    number you could easily write code to read the integer part, store it,
    and then store the fractional part. So 5.25 might be x0=5 and x1=250,
    for example.

    However, doing any sort of math like that is likely to be frustrating.
    You can sometimes "scale" things to work out. So, for example,
    converting F to C is:

    F=1.8*C+32

    You could write this as:

    F = (18*C)/10+32

    Further, supposed you wanted the answer to 1/10 of a degree. You could
    write:

    F = 18*C+320

    So if you temp (C) was 100, the answer would be 2120. You could even
    say:

    Fint = F/10 ' Fint = 212
    Ffrac = F%10 ' Ffrac = 0

    Of course, another answer is to use one of our math coprocessors like
    the PAK-I, II, or IX (see http://www.al-williasm.com/pak1.htm for
    details). These give you 32-bit floating point math with all the
    operations you'd expect.

    Al Williams
    AWC
    * Control 8 servos at once
    http://www.al-williams.com/awce/pak8.htm



    >
    Original Message
    > From: jbrobertsman [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=SKV0qRb-SP24ipjEP3RGpjJtjSQChxvrMjiWVBDeuYIkjGGdP8aSVqucP8C3IsOYB0NKEZNogtqh_5oZYlz7]JBRobertsman@a...[/url
    > Sent: Wednesday, November 13, 2002 9:04 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Numbers with Decimal Points
    >
    >
    > Hi All...thanks to all for answering my questions. I have another
    > question:
    >
    > My BASIC manual says it cannot handle decimal point entries. I am
    > writing an application which would need a number with a decimal point
    > entered from the keyboard and then compared later to an actual
    > measured value. Anyone have any ideas on how to program this ?
    >
    > Thanks for all you help...JB
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 19:47
    Al...thanks for your response

    All I want to do is be able to enter a decimal point number from the
    keyboard into the BS2 and store it. The stored number will then be
    compared to an actual measured value. I am a unsure the best way to
    program this functionality. Do you have any ideas ?

    Thanks...JB


    --- In basicstamps@y..., "Al Williams" <alw@a...> wrote:
    > It depends on exactly what you need to do. If you just need to
    store the
    > number you could easily write code to read the integer part, store
    it,
    > and then store the fractional part. So 5.25 might be x0=5 and
    x1=250,
    > for example.
    >
    > However, doing any sort of math like that is likely to be
    frustrating.
    > You can sometimes "scale" things to work out. So, for example,
    > converting F to C is:
    >
    > F=1.8*C+32
    >
    > You could write this as:
    >
    > F = (18*C)/10+32
    >
    > Further, supposed you wanted the answer to 1/10 of a degree. You
    could
    > write:
    >
    > F = 18*C+320
    >
    > So if you temp (C) was 100, the answer would be 2120. You could even
    > say:
    >
    > Fint = F/10 ' Fint = 212
    > Ffrac = F%10 ' Ffrac = 0
    >
    > Of course, another answer is to use one of our math coprocessors
    like
    > the PAK-I, II, or IX (see http://www.al-williasm.com/pak1.htm for
    > details). These give you 32-bit floating point math with all the
    > operations you'd expect.
    >
    > Al Williams
    > AWC
    > * Control 8 servos at once
    > http://www.al-williams.com/awce/pak8.htm
    >
    >
    >
    > >
    Original Message
    > > From: jbrobertsman [noparse][[/noparse]mailto:JBRobertsman@a...]
    > > Sent: Wednesday, November 13, 2002 9:04 AM
    > > To: basicstamps@y...
    > > Subject: [noparse][[/noparse]JUNK] [noparse][[/noparse]basicstamps] Numbers with Decimal Points
    > >
    > >
    > > Hi All...thanks to all for answering my questions. I have another
    > > question:
    > >
    > > My BASIC manual says it cannot handle decimal point entries. I am
    > > writing an application which would need a number with a decimal
    point
    > > entered from the keyboard and then compared later to an actual
    > > measured value. Anyone have any ideas on how to program this ?
    > >
    > > Thanks for all you help...JB
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@y...
    > > from the same email address that you subscribed. Text in the
    > > Subject and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 19:50
    Hi Tracy...thanks for your response

    I just wrote a reply to Al's response on what I want to do. If after
    reading it you have any ideas, I would surely appreciate it ? I am
    not a pro programmer and am learning everyday

    Thanks...JB

    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Hi All...thanks to all for answering my questions. I have another
    > >question:
    > >
    > >My BASIC manual says it cannot handle decimal point entries. I am
    > >writing an application which would need a number with a decimal
    point
    > >entered from the keyboard and then compared later to an actual
    > >measured value. Anyone have any ideas on how to program this ?
    > >
    > >Thanks for all you help...JB
    >
    > Lets say you need 2 decimal places. Then in your program, work
    with
    > 100* all th e values.
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 21:15
    >Al...thanks for your response
    >
    >All I want to do is be able to enter a decimal point number from the
    >keyboard into the BS2 and store it. The stored number will then be
    >compared to an actual measured value. I am a unsure the best way to
    >program this functionality. Do you have any ideas ?
    >
    >Thanks...JB


    Here's a starter. The serin command gets two values, xi and xf,
    before and after the decimal point. The Stamp treats the decimal
    point as a terminator for data entry. Then xi and xf are combined to
    make one bigger number (your value *100). That is used for the
    comparison. The demo also shows one way to print out the "measured"
    value with a decimal point.


    xi var byte ' integer part, hundreds
    xf var byte ' fractional part, hundredths
    xx var word ' whole thing, *100
    y con 1234 ' for comparison

    loop:
    debug "enter a number xx.xx> "
    serin 16,$54,[noparse][[/noparse]dec xi,dec xf] ' for BS2
    xx = xi*100 + xf
    comparison:
    if xx>y then debug cr,"is greater than "
    goto showy
    debug cr,"is less than or equal to "
    showy:
    debug dec y/100,".",dec2 y,cr
    goto loop

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-15 15:07
    Thanks Tracy...works great now ! As soon as I know enough to help
    other folks out on this forum I will...but don't expect it soon !!!

    Thanks for everyone's help...JB

    --- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
    > >Al...thanks for your response
    > >
    > >All I want to do is be able to enter a decimal point number from
    the
    > >keyboard into the BS2 and store it. The stored number will then be
    > >compared to an actual measured value. I am a unsure the best way to
    > >program this functionality. Do you have any ideas ?
    > >
    > >Thanks...JB
    >
    >
    > Here's a starter. The serin command gets two values, xi and xf,
    > before and after the decimal point. The Stamp treats the decimal
    > point as a terminator for data entry. Then xi and xf are combined
    to
    > make one bigger number (your value *100). That is used for the
    > comparison. The demo also shows one way to print out
    the "measured"
    > value with a decimal point.
    >
    >
    > xi var byte ' integer part, hundreds
    > xf var byte ' fractional part, hundredths
    > xx var word ' whole thing, *100
    > y con 1234 ' for comparison
    >
    > loop:
    > debug "enter a number xx.xx> "
    > serin 16,$54,[noparse][[/noparse]dec xi,dec xf] ' for BS2
    > xx = xi*100 + xf
    > comparison:
    > if xx>y then debug cr,"is greater than "
    > goto showy
    > debug cr,"is less than or equal to "
    > showy:
    > debug dec y/100,".",dec2 y,cr
    > goto loop
    >
    > -- Tracy
Sign In or Register to comment.