So I’ve ran into some issues recently, and I’m rounding numbers because otherwise I can’t get the RGB color I want as I’m converting from HSV to RGB and normally get long decimals that I want rounded but whenever I try methods of rounding they don’t seem to do much.
Type of numbers I want to round with no decimals: <font color= "rgb(255, 141.09342956543, 73.87370300293)">l</font>
Floating-point errors are not fixable, but can be mitigated. Mitigation is however tedious. If you are talking about numbers that contain 1.00000000024729011 or something like that. It’s never going away.
local function BRUHMOMENT(numb)
local a,b = math.modf(numb)
if b < 0.5 then
return a
else
return a + 1
end
end
print(BRUHMOMENT(34999.654354665454634563654345636453))
print(BRUHMOMENT(34999.454354665454634563654345636453))
print(BRUHMOMENT(34999.5))
I am pretty sure OP can use math.floor on the floating point number, to get the integer, can’t they?
Like that?:
local rounded = math.round(141.09342956543) --Round the number
local roundedInteger = math.floor(rounded) --No floating point?
Also, I don’t know how math.round works behind the scenes, but I believe you can also do math.floor(number+0.5)
This way, when the number’s decimal is larger or equal to/than 0.5, it’ll round to the larger number, and when smaller, to the same number without (the Integer).
Both ways (math.round then floor, or floor+0.5) should work
Edit: math.round is supposed to return an integer too. I wonder if using math.floor on the floating point error actually fixes it. (when both return integers)