Best-Killer Posted January 15, 2016 Share Posted January 15, 2016 How To Convert String to Number Link to comment
AMARANT Posted January 15, 2016 Share Posted January 15, 2016 Haha, lol) Man it's: tonumber Link to comment
Noki Posted January 15, 2016 Share Posted January 15, 2016 If you're trying to convert from user input, I'd recommend cleaning the string, so to speak. str = str:gsub(" ", "") -- Remove whitespace as a precaution str = str:gsub(",", "") -- Some people feel the need to do this str = tonumber(str) -- If tonumber cannot convert, it will return nil if (str) then str = math.abs(str) -- 6.480000000000 becomes 6.48. I've had cases where people were crashing other's MTA clients with numbers that had many zeroes on the end. end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now