How do I convert a string to a number?

Get help using Construct 2

Post » Sat May 24, 2014 3:43 am

If I have a text variable that's equal to "95", is there a way I can convert that string to its numerical equivalent so I can manipulate it as a number?

Thanks
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Sat May 24, 2014 3:56 am

Heh, I assumed there was some native expression like "NumberVariable = ToNumber("99") but Construct 2 is smarter than I thought.

I can simply assign the string to a number variable and it converts it.
It converts a straight number like "99" and even a combination like "99apples". It knows to just capture the 99.
It doesn't like this obviously "apples" or "apples99"
And if you give it something like "99apples100", then it just picks the "99".

Lesson learned!
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Sat May 24, 2014 12:13 pm

There's also int("string") and float("string").
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests