View Single Post
Old 08-14-2019, 10:26 AM   #3
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,251
Default

It's probably easiest to just do a string match and then cast it back to an integer.
Code:
local num = -9.12
local output = string.gsub(num, "%d+%.", "")
--> -12
If it's useful to have them separately, you can also do:
Code:
local sign, dec = string.match(num, "([^%d]?)%d+%.(%d+)
--> -, 12
Note: In either case, the output will be a string.
Lokasenna is online now   Reply With Quote