hi , is there a way to polish values? because my calculator script make things like 283.873867836386387, is there a way to make it so its just 283?
so i do thing.Value = something / 2.38 and then math.floor(thing.Value)?
so this would be right? : S4P.Value = math.floor(S4P.Value)
but what does math.floor normally does?
Math.floor returns the largest smaller integer you call it with. For more information about the math library, read here: lua-users wiki: Math Library Tutorial
yeah thats what i need, doing math.floor on 1.2927 would do 0 or 2
Oh sorry, I think I misread your original question. Call math.floor without adding 0.5 and you should be good.
Calling math.floor on 1.2927 will return 1.
If you read over the math page on the developers hub there are a few math methods you can use to do this: math | Documentation - Roblox Creator Hub.
math.ceil:
In short this will always round the number up. Here is a little example:
local Number = math.ceil(1.2344)
print(Number)
-- prints 2
math.floor:
In short this will always round the number down. Here is a little example:
local Number = math.floor(1.62344)
print(Number)
-- prints 1
There’s also math.modf which will literally separate the integral and the fractional part of a number. You can use this and discard the fractional if you’re uninterested in rounding.
local number = 283.873867836386387
local integral = math.modf(number)
print(integral) -- 283
*edit: This is functionally identical to math.floor so you should just use that, actually.
Alternatively if you want to round like they taught in grade school you’d do something like
local RoundedNumber = math.floor(Num + .5);
For this use case, this functions identically to math.floor
, as floor
rounds down no matter what, getting rid of the decimal and leaving the integer.
Best way of achieving polish values is this.
local number = 0.4
print(math.floor(number + 0.5)) -- 0
local number = 0.5
print(math.floor(number + 0.5)) -- 1
local number = 1.1
print(math.floor(number + 0.5)) -- 1
local number = 1.6
print(math.floor(number + 0.5)) -- 2