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

  • 4 Comments sorted by Date Added Votes
  • something like:
       singles := number//10
       tens := (number/10)//10
       hundreds := (number/100)//10
       thousands := number/1000
    
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
  • @tomcrawford

    Thank you
    I will give ita try

    Siri
  • JonnyMacJonnyMac Posts: 6,092
    edited August 6 Vote Up0Vote Down
    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)
    
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • Of course, it you want to fiddle with larger numbers you can use this from OBEX.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
Sign In or Register to comment.