Shop OBEX P1 Docs P2 Docs Learn Events
Shifting data — Parallax Forums

Shifting data

ArchiverArchiver Posts: 46,084
edited 2004-03-31 19:20 in General Discussion
Hi!

Anybody out there know of a way of shifting data 2 decimal places,
left or right, for DECIMAL data...?

ie. 123 would become 0.123 if it were moved three decimal places.

I know it can be done when using Binary data but how can this be done
with decimal data - if at all????

Kate.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-03-31 16:19
    Just multiply or divide by 100.
    123 /100 = 1.23
    123 *100 = 12300
    (or am I missing something here?)

    --- In basicstamps@yahoogroups.com, "lonkl" <Kate.long@c...> wrote:
    > Hi!
    >
    > Anybody out there know of a way of shifting data 2 decimal places,
    > left or right, for DECIMAL data...?
    >
    > ie. 123 would become 0.123 if it were moved three decimal places.
    >
    > I know it can be done when using Binary data but how can this be
    done
    > with decimal data - if at all????
    >
    > Kate.
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-31 16:20
    Arbitrary answer: divide by 100 (or 1000, you said 2 places and 3 places).
    Of course, the Stamp will compute 123/100=1. Here's another idea (not
    tested):

    For i=4 to 0
    debug dec1 x dig I
    if i=2 then
    debug "."
    endif
    Next

    So if x=234 you would get 002.34 from this. Supressing leading zeros is an
    exercise left for the reader :-)

    Of course, you could add a floating point coprocessor (like our new PAK-XII)
    to the mix and actually compute x/100 and get a float back out.

    Regards,

    Al Williams
    AWC
    * New floating point math & A/D:
    http://www.awce.com/pak12.htm




    Original Message
    From: lonkl [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=8Pk8BBwJiiBaIx9M9bQUsNVZm4tegk08Vi20EZfnXPw7nc0B60dYC9x3E3wVtnMEuY7VCBQc69XzZ5ToKw]Kate.long@c...[/url
    Sent: Wednesday, March 31, 2004 4:59 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] Shifting data


    Hi!

    Anybody out there know of a way of shifting data 2 decimal places,
    left or right, for DECIMAL data...?

    ie. 123 would become 0.123 if it were moved three decimal places.

    I know it can be done when using Binary data but how can this be done
    with decimal data - if at all????

    Kate.





    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.

    Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-31 16:34
    thanks for that....I will try it tonight.

    --- In basicstamps@yahoogroups.com, "Al Williams" <alw@a...> wrote:
    > Arbitrary answer: divide by 100 (or 1000, you said 2 places and 3
    places).
    > Of course, the Stamp will compute 123/100=1. Here's another idea
    (not
    > tested):
    >
    > For i=4 to 0
    > debug dec1 x dig I
    > if i=2 then
    > debug "."
    > endif
    > Next
    >
    > So if x=234 you would get 002.34 from this. Supressing leading
    zeros is an
    > exercise left for the reader :-)
    >
    > Of course, you could add a floating point coprocessor (like our new
    PAK-XII)
    > to the mix and actually compute x/100 and get a float back out.
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > * New floating point math & A/D:
    > http://www.awce.com/pak12.htm
    >
    >
    >
    >
    >
    Original Message
    > From: lonkl [noparse][[/noparse]mailto:Kate.long@c...]
    > Sent: Wednesday, March 31, 2004 4:59 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Shifting data
    >
    >
    > Hi!
    >
    > Anybody out there know of a way of shifting data 2 decimal places,
    > left or right, for DECIMAL data...?
    >
    > ie. 123 would become 0.123 if it were moved three decimal places.
    >
    > I know it can be done when using Binary data but how can this be
    done
    > with decimal data - if at all????
    >
    > Kate.
    >
    >
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-31 19:20
    Kate,

    What are you going to do with it, once you shift it? If you only
    need to print it out on the screen, you can use modifier statements
    like the following:

    DEBUG DEC X*100 ' for 0<=x<=655 only
    DEBUG DEC x/100,".",DEC2 x ' 0.00 to 655.35

    If you need to use the shifted value in a subsequent calculation,
    that is a different matter. You have to keep track of the position
    of the decimal point "on the side", and maybe even go to double
    precision (32 bits) if necessary.

    -- Tracy



    >Hi!
    >
    >Anybody out there know of a way of shifting data 2 decimal places,
    >left or right, for DECIMAL data...?
    >
    >ie. 123 would become 0.123 if it were moved three decimal places.
    >
    >I know it can be done when using Binary data but how can this be done
    >with decimal data - if at all????
    >
    >Kate.
Sign In or Register to comment.