✓ Accepted answer
local n = 7.2;
local function convert (number)
local length = tostring(number):len();
local x = number;
local y = 1;
local a = "1";
for i = 1, length do
a = a .. "0";
end
a = tonumber(a);
x = x * a;
y = y * a;
for i = x, 1, -1 do
local c = x / i;
local d = y / i;
if (c == math.floor(c) and d == math.floor(d)) then
return c, d;
end
end
end
local function convertToWhole (x, y)
local total = 0;
local x = x;
for i = x, 1, -1 do
if x >= y then
x = x - y;
total = total + 1;
end;
end
local a = total;
local b = x;
local c = y;
return a, b, c;
end;
local a, b, c = convertToWhole(convert(n));
print(string.format("%d %d / %d", a, b, c));
5 comments
Sorry, what couldn't you get a decimal to do?
let's say the decimal is 7.2. That would be 7 and 2/3 but it goes as 7 and 2/10. I don't want this.
Maybe you want to use a base 3 float. You will need a base changing function for that.
I updated it to your actual problem.
Tbh I probably should have used my main account. Oh well lol.