# How do I get the digits of a value from global variable.

Get help using Construct 2

### » Mon Mar 17, 2014 1:06 am

I need to get them separetly to insert the number in the Variables Digit1, Digit2 and Digit3. However, I have no clue how to do that.

Could someone enlighten me?
B
59
S
21
G
3
Posts: 604
Reputation: 6,691

### » Mon Mar 17, 2014 3:04 am

if you have a
Code: Select all
`global number MyNumber = 123456`

For any digit n (counting from 0) from the right the formula would be:
Code: Select all
`floor(MyNumber/10^n)%10`

for example:
Code: Select all
`floor(MyNumber/10^0)%10  -> 6floor(MyNumber/10^1)%10  -> 5floor(MyNumber/10^2)%10  -> 4... etc`
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

### » Mon Mar 17, 2014 3:28 am

@Yann

Could you please, explain me what these operators does(^, %)?I just know what floor expression does. I'm looking at the tutorials but I couldn't understand.

B
59
S
21
G
3
Posts: 604
Reputation: 6,691

### » Mon Mar 17, 2014 3:36 am

^ is the exponent operator
Code: Select all
`10^0 = 110^1 = 1010^2 = 100etc...`
now in the formula, the / 10^n just set the digit you want to be the first digit.

% is the modulo operator
It's formal definition would be that it's the remainder of the euclidean division of two numbers
for example:
Code: Select all
`5 : 3 = 1 with remainder 2`

If you don't like this explanation you can also look at how it behaves according to different input to get a feel for it (after all we're not mathematicians)
for example:
Code: Select all
`0%3 = 01%3 = 12%3 = 23%3 = 04%3 = 15%3 = 26%3 = 0etc.(see how things cycle?)`
now in the formula, the % 10 just gives you the first digit of any number
Last edited by Yann on Mon Mar 17, 2014 1:58 pm, edited 1 time in total.
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

### » Mon Mar 17, 2014 4:05 am

@Yann

I got it. Man, I love you. That's so cool!

Now i'm going to see how I'll put this into my event sheet.

Yes, I'm not a mathematician, I'm a grafic designer with an old passion to make my own game.

Thank you a lot, man. I'm very grateful.
B
59
S
21
G
3
Posts: 604
Reputation: 6,691