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 )
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
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)
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.