Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

1

use int value instead, do volume = volume + 1 / 10 it will get you 0.1

0

math.floor(x) can help you

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.