I would suggest to use math.eval and call basic function to do the calculation. But sadly enough getNum and getDenom don't work good through math.eval.
But ... gcd() (greatest common divisor) does, so I made my own function:
function exact(n)
local n_int, n_float = math.modf(n)
local n_size = math.pow(10, #tostring(n_float)-2)
local num = n_float * n_size
local denom = n_size
local gcd = math.eval("gcd(" .. num .. "," .. denom .. ")")
num = num/gcd
denom = denom/gcd
return n_int, num, denom
end
It works like this:
big, num, denom = exact(13.125)
big will be 13
num will be 1
denom will be 8
So, 13 1/8 .
It doesn't do any error checking though, thats your task :p