Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to round off number into 2 decimals?

Asked by 1 year ago

I have a simple script which show's the humanoid data such as JumpPower and WalkingSpeed. My problem is that if the value show more than 2 decimals then the Gui can't show it.

What I need is something that only show 2 decimals, I hope you guys understand what I mean.

1 answer

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
1 year ago
Edited 1 year ago

you can try these

local Value = 37.7777779

local rounded_down = math.floor(Value*100)/100 --Result: 37.77
local rounded_up = math.ceil(Value*100)/100 --Result: 37.78
local nearest = math.round(Value*100)/100 --Result: 37.78
print(rounded_down)
print(rounded_up)
print(nearest)
0
Does the number only show 2 decimals? What if I want to show 3 decimals? I'm just curious this time. Btw thank you. AltairCelestia 47 — 1y
0
change 100 to 1000 if you run it in a lua interpreter the numbers will shift Puppynniko 1059 — 1y
0
Oww, thanks once again AltairCelestia 47 — 1y
0
:D Puppynniko 1059 — 1y
Ad

Answer this question