Counting the number of numbers, in a number
grasshopper
Posts: 438
I am trying to count how many numbers I have in a number. For example the number 1562 has 4 numbers the 1,5,6,2. I can do this using math and logic, but I wanted to know if there was any other way to achieve this preferably with out using any math or divide statements.
Thanks
Thanks
Comments
I don't think there is a simple one-shot process for doing this, but I'm probably wrong... people on this forum amaze me with their tricks consistantly.
I think it can't be done within one line
if you don't want a loop
you could use a case-construction
case MyVariable
1..9
10..99
100...999
etc.
but I think the best way is the way like the method "DEC" in the FullDuplexSerial-object does it
Your asking for ONE detail. What is it good for ? If you describe your COMPLETE target there might be still other ways to achive it
best regards
Stefan
That might be what I am looking for. Currently I use a bit of math and have to float not float etc. Ill test this today. Thanks
I am at work, and my P'lax stuff is home, so I'm not too sure of the syntax. Also, I've done a sheet-of-paper check, and I BELIEVE the algorithm is good, but "buyer beware"!
--Rich
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
If X >= 1000 Then
· Count = 4
ElseIf X >= 100 Then
· Count = 3
ElseIf X >= 10 Then
· Count = 2
Else
· Count = 1 'Zero counts as one digit
End If