Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I turn a string value into a int value?

Asked by
sydre 229 Moderation Voter
5 years ago

Simple question, how do I turn a string value into a int value. In Python, the programming languages I'm most comfortable with, you simple write:

strvalue = "3"

toadd = 7

strvalue = int(strvalue)

total = strvalue + toadd

But how can i do this in Lua

0
There's a built-in called "tonumber" that will convert to a number type from a string type. For example; tonumber("5") --> 5 ScriptGuider 5640 — 5y
0
Just grab whats in the IntValue, then delete the invalue, then put everything in the IntValue into the number value :P WideSteal321 773 — 5y

1 answer

Log in to vote
0
Answered by
stef0206 125
5 years ago

int = tonumber(string)

0
but what if the string is "2.33" for example, that wont be an integer starmaq 1290 — 5y
0
Thanks sydre 229 — 5y
0
Well, if it's 2.33 he will just have to make a numberValue instead, makes no difference + he asked how to turn a string into an integer, and there is simply no way to make "2.33" an int, considering that an int can't have decimals stef0206 125 — 5y
Ad

Answer this question