1.05 should change to 1, 10.24 should change to 10, 349.55 should change to 349, how could i do that (Remove the numbers after “.”)?
math.floor() will return what you want
math.floor(whatever number) for rounding down
math.ciel(whatever number) for rounding up
I already did that,
without math.floor = 1.22248294582239
with math.floor = 1.22
Does not work,what i want to archivie
Have you tried math.round()
?
Might not be exactly what you want, but it should work.
Use math.floor
.
math.floor(1.05) --> 1
math.floor(10.24) --> 10
math.floor(349.55) --> 349
I used that already look at my other comments
if you always want to round down to remove the decimal then use math.floor(number), like @MUMU_ELMOUMOU said.
Okay, so this is solved then? If not, why wouldn’t math.floor work?
You want to remove every number after the decimal, so try math.round()
It rounds it to the nearest whole number (a number without a decimal)
in his original posts’ examples he says how he wants it also to convert 349.55 to 349, so he wants to truncate decimals, not round up
Fair. I forgot math.round only rounds up. Kinda false advertisement on roblox’s end
I seriously haven’t used math.round myself in months
what do you mean
well math.round rounds up and down to the nearest whole number but in this case apparently he wants it to just completely cut off any decimal regardless (truncation)
This is extremely far-fetched, clunky, unnecessary and inefficient, but you could try this:
local function removeDecimal(number)
local String = tostring(number) --// Converts the "number" variable (the number passed through the function) into a string
local splitString = String:split(".") --// Breaks the string into parts (a table) anywhere there is a period (or full stop. Whatever you call it)
return tonumber(splitString[1]) --// Converts the first thing in the table (the first part of the string, or the whole number) back into a number, then it gets returned
end
print(removeDecimal(7579.8865609)) --// A random number with a decimal to show if it works. This CAN be deleted as it's only to test
removeDecimal(1.05) --// Can be replaced with any number or any variable that equals a number
removeDecimal(10.24) --// Can be replaced with any number or any variable that equals a number
removeDecimal(349.55) --// Can be replaced with any number or any variable that equals a number
I personally wouldn’t use this, but it might work. Idk. I’m at school on my phone right now so I can’t test anything
It would be inefficient normally, but considering math.floor() didn’t work properly for you, it’s your best bet
I ain’t playing when I say I completely forgot how math.round() works
I usually only use math.floor, so my brain pretty much cleared what math.round does from my memory
Is this what you’re looking for?
local function RemoveDeci(Number)
local whole, remainder = math.modf(Number)
return whole
end
print(RemoveDeci(1.012)) --> 1
print(RemoveDeci(4.7)) --> 4
print(RemoveDeci(1.999999999999)) --> 1
print(RemoveDeci(4444.9282)) --> 4444
Im confused how you got 1.22 when math.floor() returns 1 xd