How to COMPLETELY round numbers

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>

1 Like

You should try this:

math.ceil

ceil = Round up

math.floor

floor = round down

3 Likes

There’s actually a math.round function that has been lying around for weeks. Works similar to the traditional method of rounding.

2 Likes

Oh, yeah. That’s much better than both of those

Problem is that even if I use that it gives me tons of decimals after

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.

How can I mitigate the issue since I need a precise RGB value

maybe something like this

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

Would removing anything beyond . point work as well

Uhm, I think

image

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)

1 Like

I made a Round function where you can specify the number of decimals if you want: