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

How do i remove the decimal of a number value?

Asked by
CjayPlyz 643 Moderation Voter
5 years ago
local ClickDetector = script.Parent.ClickDetector
local Ranks = {
    "Newbie",
    "Novice",
    "Rookie",
    "Beginner",
    "Talented",
    "Skilled",
    "Intermediate",
    "Skillful",
    "Seasoned",
    "Proficient",
    "Experienced",
    "Advanced",
    "Senior",
    "Expert"
}

local function OnMouseClick (Player)
    local level = Player.leaderstats.Level
    local nextlevel = level.Value + 1
    local experience = Player.stats.Experience
    local maxexperience = level.Value * 100
    local title = Player.leaderstats.Title

    experience.Value = experience.Value + ((maxexperience * 0.1)+ 3)
    print("experience : " .. experience.Value)

    if experience.Value >= maxexperience then
        print(experience.Value .. " is higher than or equal to " .. maxexperience)
        local leftexperience = experience.Value - maxexperience
        print("leftexperience : " .. leftexperience)
        experience.Value = leftexperience
        print("experience : " .. experience.Value )
        level.Value = nextlevel

        local rank = Ranks[1 + (level.Value / 5)] -- Important
        title.Value = rank
    end
end

ClickDetector.MouseClick:Connect(OnMouseClick)

How do i remove the decimal of the rank? For example if the value is 3.8 then it will become 3

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Namaste it is i, dual

Normally I would write a really in-depth answer to any question I answer, but this one requires less depth so I'll keep it short.

There are 2 basic methods to do this in the math library

(https://developer.roblox.com/en-us/api-reference/lua-docs/math)

These are math.floor() and math.ceil().

math.floor() cuts off the decimal, and return the CURRENT integer

math.floor(4.1)) -> 4
math.floor(3.8)`) -> 3

Whereas math.ceil() cuts off the decimal, and returns the NEXT integer

math.floor(4.1)) -> 5
math.floor(3.8)) -> 4

Of course, if neither of these suits your tastes, you can always create your own rounding function, however I believe math.floor() is what you're looking for.

You can read more on Lua's math library here: http://lua-users.org/wiki/MathLibraryTutorial

That is all

0
adding to this you can use strings to get a more flexible result. so it would be something like this: tonumber(string.format("%.4f", "5.509453")) GGRBXLuaGG 417 — 5y
Ad
Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
5 years ago
math.floor(number)

will return the lower value of the number, so if number is 5.9, it will be 5.

math.ceil(number)

will return the higher value of the number, so if the number is 5.1, it will be 6.

Answer this question