Seperating the digits of a number

Blitz3D Forums/Blitz3D Programming/Seperating the digits of a number

Andy(Posted 2008) [#1]
I need to get the digits of a number...

number = 245

should leave me with this...

alfa = 2
beta = 4
Ceta = 5

I know there's a really simple way of doing it, and I'm pretty sure I've seen it on here, but I just can't remember...


Naughty Alien(Posted 2008) [#2]
here ya go

Dim Number(100);your separated digits

MyNo=245
StringIt$=Str(MyNo)

For i=1 To Len(StringIt$)
If i>1
CurString$=Right$(CurString$,Len(CurString$)-1)
Else
CurString$=StringIt$
End If

Number(i)=Left$(CurString$,1)
Next

For i=1 To Len(stringit$)

Print Number(i)
Next

WaitKey
End


Andy(Posted 2008) [#3]
Thanks naughty... A very compact and simply suggestion it is.

I forgot to say that I need it to be done purely using numbers, not using strings...

EDIT* Problem solved

test=357

ceta=test Mod 10 : test=test-ceta
beta=(test Mod 100)/10 : test=test-(test Mod 100)
alfa=test/100

Thanks naughty :)