how to round parts in roblox studio code example

Example 1: how to round numbers roblox studio

local roundDecimals = function(num, places) --num is your number or value and places is number of decimal places, in your case you would need 2
    
    places = math.pow(10, places or 0)
    num = num * places
   
    if num >= 0 then 
        num = math.floor(num + 0.5) 
    else 
        num = math.ceil(num - 0.5) 
    end
    
    return num / places
    
end

print(roundDecimals(142.165, 2)) --> 142.17

Example 2: how to round numbers roblox studio

local Number = 0  -- put your number here
TextLabel.Text = string.format('%.2f%% of Speed', Number)

Tags:

Misc Example