Creating a fraction or ratio with two number values?

How would I get the ratio of two random numbers like 32.0435 and 46.1353 with code?

( its late so this may be a silly question )

I don’t really understand the question. Do you want a random number? Do you want to calculate the ratio of 2 numbers? Do you want something else?

The ratio of two numbers

Divide the 2 numbers? ie: x/y

1 Like

If you want to find the numerator and denominator:

This might be what you’re looking for: Convert Decimals to Fractions
On a side note, though, you’ll have to remember to store the numerator and denominator separately because there isn’t a “fraction” data type.

If you want to find the ratio:

Divide 32.0435 by 46.1353

print(32.0435/46.1353)

1 Like

What do you mean? Like this?

local num1 = math.random()
local num2 = math.random()
local ratio = num1/num2
print(ratio)

As seen by the previous replies, ‘ratio’ could refer to a number of things. However, I can think of at least one example that hasn’t been shown. If by ‘ratio’ you’re referring to something like a 1-to-4 ratio (visualized as 1:4) then you can calculate this as seen in this code below:

local num1 = math.random(1, 100)
local num2 = math.random(1, 100)
local ratio = num2/num1
print("num1: " .. num1)
print("num2: " .. num2)
print("ratio 1:" .. ratio)

Tried to make a more complicated ratio calculator though I’m unable to get it working at the moment. I’ll update if I get it working.