Shop OBEX P1 Docs P2 Docs Learn Events
Programing help in spin — Parallax Forums

Programing help in spin

I would like to find out how many thousands,hundreds,tens and singles in a number Ex: 6476, and place each category in varibles Ex: singles,tens,hundreds and thousands

Any help with an example in spin will be greately appriciated.

Thank you.

Siri

Comments

  • something like:
       singles := number//10
       tens := (number/10)//10
       hundreds := (number/100)//10
       thousands := number/1000
    
  • @tomcrawford

    Thank you
    I will give ita try

    Siri
  • JonnyMacJonnyMac Posts: 9,104
    edited 2018-08-06 19:21
    Tom's code works (I tested) -- I borrowed from it to create this method that lets you set the number of digits captured from a value, always starting from the 1s end.
    pub get_digits(value, digits, p_digits)
    
      repeat digits
        byte[p_digits++] := value // 10
        value /= 10
    
    This works, too. Call it like this:
      get_digits(myValue, 4, @singles)
    
  • Of course, it you want to fiddle with larger numbers you can use this from OBEX.
Sign In or Register to comment.