How to change strings like "1/4" into floats?

Discussion and feedback on Construct 2

Post » Sat Oct 20, 2012 10:34 pm

How can I change strings like "1/4" and "5/10" into floats 0.25 and 0.5?
I've tried to use expression float(), but float("1/4") returns 1, and float("5/10") returns 5.tecbug2012-10-20 22:40:52
B
55
S
14
G
10
Posts: 287
Reputation: 7,677

Post » Sat Oct 20, 2012 11:44 pm

float(tokenAt("1/4", 0, "/")) / float(tokenAt("1/4", 1, "/"))

float(tokenAt("5/10", 0, "/")) / float(tokenAt("5/10", 1, "/"))
B
55
S
28
G
19
Posts: 1,520
Reputation: 25,540

Post » Sun Oct 21, 2012 2:13 am

thats pretty slick. nice
B
16
S
6
G
5
Posts: 90
Reputation: 4,324

Post » Mon Oct 22, 2012 10:35 am

Thank you. Works perfectly
B
55
S
14
G
10
Posts: 287
Reputation: 7,677


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests