separating individual digits of decimal number
What I would like achieve is to separate the individual numerals of a decimal number.
Like variable x value = 1234
the individual numerals 1,2,3,4 in different variables.
example : to place 1 in a variable a, 2 in a variable b and 3 in a variable 3 etc.
Thank you.
Siri
Like variable x value = 1234
the individual numerals 1,2,3,4 in different variables.
example : to place 1 in a variable a, 2 in a variable b and 3 in a variable 3 etc.
Thank you.
Siri

Comments
Anyway in spin you can split a number into the last digit and the rest with / and // operators -
repeat digit := value // 10 value /= 10 until value == 0or something like that - the remainder gives the last digit, then divide by ten and repeat - unfortunatelythat yields them in the wrong order for most uses. If you are only interested in, say, 3 digits its easy
to pick them out:
Thanks for you help.I was looking at the code from a clock and then I thought may be there are better ways.
Thanks again for the quick answers.
Siri
pub dig(value, pos) '' Returns digit from pos (0..9) of value if ((pos < 0) or (pos > 9)) return 0 repeat pos value /= 10 return ||value // 10Thanks for the code snippet.Looks very elegant.Will give it a try.
Siri