How would I round a players health to the nearest whole?

I can’t find anything about rounding

	script.Parent.Text = "Health: ".. game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health	

I have a script that shows your health on a gui but when the player regens it goes like 99.3453694573
and it’s pretty annoying so im tryna round to nearest whole

use math.floor. It does what u want

script.Parent.Text = "Health: ".. math.floor(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health	

If you have any questions then feel free to ask

Do what @kinglol123468 mentioned, but use math.round since it rounds to the nearest whole #, so 5.6 will round to 6.
math.floor will take 5.6 and drop it to 5.

1 Like

you could do both. But i just used math.floor

print(math.floor(Number + 0.5))

I recommend using math.round, it was made for this thing
you could use math.ceil, but it wouldn’t be that good

function Round(Number)
    Number -= 0.5

    return math.ceil(Number % 1 == 0 and Number + 1 or Number)

please don’t use that function

But for accuracy you should use math.round as I and @D0RYU mentioned.

math.floor will take every value from (for example) 2.000000 up to 2.999999 and make it 2.

math.round will take every value from 2 up to 2.49999999 and make it 2, while everything from 2.5 up to 3 will be made 3.

1 Like

math.ciel , you always wanna round float to int up especially considering health, sorry @Scottifly i replied to the wrong dude mb :sweat_smile:

I didn’t know that. Though im still going to use math.floor so it just deletes the decimals. I dont need it to round.

But @cookthedev asked for something that rounds to the nearest integer which math.floor doesn’t do.

From the math | Roblox Creator Documentation page:
math.round Returns the integer
An integer has no decimal.

Try it out.

1 Like

I was talking about myself. Not about him.

math.ceil, math.floor, and math.round remove all the decimals/fractions

Look here loloololol