I have a decimal number that goes from 0 to 1, how do I limit this number to where 0 would end up as 0.33 and 1 would end up as 0.66? Pardon me if this is an easy solution as I haven’t learned maths in a few years.
1 Like
You’re talking about fraction digit precision right?
It should be straightforward, variable value
is the value to round by precision and prec
is the fractional digits precision
math.round(value * (10 ^ prec)) / (10 ^ prec)
No, I mean where if I had a function and passed a value of 0 into it, it would return 0.33, but if I passed a value of 1 it would return 0.66 and if I passed anything inbetween 0-1 it would return something inbetween 0.33-0.66. I made an illustration for what I mean:
local function round(number, base)
return math.floor(number/base + 0.5)*base
end
local Result = round(x, 1/3) -- where x is your number
I hope this helps
Oh just understand what you want. but looks like @Middoken already answered but if you want to know the formula here it is:
To map
[A, B] --> [a, b]
use this formula
(val - A)*(b-a)/(B-A) + a
local Min=0.33
local Max=0.66
local At=0.5
local Result=Min+(Max-Min)*At
^
Will return 0.495 just like in the image example you sent above
3 Likes
Just do
math.random(33,66)/100
Perfect! Exactly what I wanted. Thank you