Shop OBEX P1 Docs P2 Docs Learn Events
Need to output to be in 5’s — Parallax Forums

Need to output to be in 5’s

TCTC Posts: 1,019
edited 2014-01-10 16:34 in Propeller 1
I am trying to figure the best way to take a value and change it into steps of 5’s. For example:
Starting value : what I want
4 : 0
6 : 5
11 : 5
12 : 10
24 : 20
26 : 25
I hope this makes sense.
Thanks
TC

Comments

  • ChrisGaddChrisGadd Posts: 310
    edited 2014-01-10 13:16
    Something like x := (x / 5) * 5?
  • TCTC Posts: 1,019
    edited 2014-01-10 13:21
    ChrisGadd wrote: »
    Something like x := (x / 5) * 5?

    Yep, like that. I never thought of that, still learning. Thanks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-01-10 13:22
    Should "11 : 5" be "11 : 10"?

    If so then what CG just wrote would work. An alternative way would be:
    x -= x // 5
    

    My code is shorter, does that mean I win?
  • TCTC Posts: 1,019
    edited 2014-01-10 14:39
    Duane Degn wrote: »
    Should "11 : 5" be "11 : 10"?

    If so then what CG just wrote would work. An alternative way would be:
    x -= x // 5
    

    My code is shorter, does that mean I win?

    OOPS, Yes, it should be 11 : 10

    I like yours, but ChrisGadd's is easier for me to understand what is going on.
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2014-01-10 15:07
    If there's no obvious mathematical relationship, would a lookup table be a solution?
  • TCTC Posts: 1,019
    edited 2014-01-10 16:34
    Ken Gracey wrote: »
    If there's no obvious mathematical relationship, would a lookup table be a solution?

    That was one of my ideas, but how would would I do that? the value would be anywhere from 0 to 50, but I only care about steps of 5.
Sign In or Register to comment.