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

[SOLVED]How do i round off a number to 0.?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a background music volume setting.

The current script is this:

script.Parent.MouseButton1Click:Connect(function()
    if game.SoundService.BackgroundMusic.Volume <= 1 then
        game.SoundService.BackgroundMusic.Volume = game.SoundService.BackgroundMusic.Volume + 0.1
        script.Parent.Parent.Value.Text = game.SoundService.BackgroundMusic.Volume
    elseif game.SoundService.BackgroundMusic.Volume == 1 then
        return
    end
end)

I have some text that displays the current volume of the background music. But everytime i change the volume with the script. It changes to 0.00000142141.

I want to change it so it's just 0.1

Thanks.

1
use int value instead, do volume = volume + 1 / 10 it will get you 0.1 greatneil80 2647 — 5y
0
math.floor(x) can help you piRadians 297 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
function round(num, numDecimalPlaces)
    local mult = 10^(numDecimalPlaces or 0)
    return math.floor(num * mult + 0.5) / mult
end

This is just an example. The variable numDecimalPlaces is how many decimal places you want to round to (you want one place for your script, I bet). The variable num is the number you want to round.

Ad

Answer this question