How do I truncate a NumberValue properly?

This is because of floating point math. There is a topic that discusses it here. This shouldn’t have any large effect on your game, and it shows you the computer’s interpretation of the value. If you were set a numberValue to 0.4 and print it, you would get 0.4. Using stringvalues can work, but over time that can create errors with math, so unless this math isn’t too necessary I would personally just leave it, as players aren’t going to see the numbervalue’s value, and if they are, using string.format("%.2f", Value) or; like scripton said in the topic: using string values and tonumber to solve this.

Simple rounding function that makes sure you don’t get something like 4.00 if you input a 4:

local function Round(number)
    if math.floor(number) ~= number then
        return string.format("%.2f", number)
    end
end
1 Like