Hello Devs, I need help. I want to change a number (for example: 1.123456789) to a number more smaller (example: 1.123456789 → to this 1.1).
how can I do that?
Please help
Hello Devs, I need help. I want to change a number (for example: 1.123456789) to a number more smaller (example: 1.123456789 → to this 1.1).
how can I do that?
Please help
Got this little snippet of code I’ve wrote one time for another post… some other person provided a snippet faster that was also more efficient before I could but here:
local function convert(num, stopAt)
local strNum = tostring(num)
local pos = string.find(strNum, "%.")
strNum = string.sub(strNum, pos, pos + stopAt)
return tonumber(string.gsub(tostring(num), "%.%d+", strNum), 10)
end
print("Final result:")
print(convert(1.5662, 2))
-- stop at hundredths
-- 1.56
Although you can search up “Decimal rounder Roblox” and you’ll find it eventually (its more efficient than mines)
This is what I use when I’m trying to round to a decimal and I believe it is more efficient than D00M3D’s
This is my first comment so sorry if I did anything wrong.
local function Rounding(Number,NumbersDisplayed)
local Acc = (0.5/(10^NumbersDisplayed))
local Mod = (1/(10^NumbersDisplayed))
return ((Number+Acc)-((Number+Acc)%Mod))
end
print(Rounding(1.123456789,1)) -- 1.1```
This seems wayy more complicated but it might be more efficient (not gonna test it though).
This wasn’t exactly the one I was mentioning in my post which is also still less complicated than @madHacker100‘a solution; but props to you!
Thanks once again it’s my first comment lol, I just care about performance too much
thanks for being so nice ![]()
Thanks you so much ![]()
It worked!