Alright, so, basically, I made a script so when you die, it divides your money by half, however, this method brings a bad result, which is, let me actually provide an example since I'll probably confuse all of you.
1.2< The arrow marks the part that I want to get rid of, can anyone tell me how to do that? I thought about using string.Sub() but I have no idea how to use it after all, anyways, I would appreciate if anyone would've been able to teach me this.
Thanks!
There's a neat trick you can do with math.floor(). Below is an example.
local number = 1.2 local rounded = math.floor(number + 0.5)
This will round the value to the nearest whole number from which I assume you are trying to do. It works because math.floor() always returns the number without the decimal. You then add 0.5 so that if the number is above 0.5, it'll get rounded above.
Just want the decimal to be removed?
local number = 1.2 local rounded = math.floor(number)
This should work. If it doesn't, leave a comment. If it does, make sure to mark this question as the accepted answer.
You can read more about math.floor() here.
local n1 = 1.2 local n2 = 1.6 local function round(n) return math.floor(n + 0.5) end print(round(n1)) print(round(n2))
this will print 1 2