- Home /
4.6 Slider round to int?
So I am using a slider for audio and as you know the volume has to be from 0-1. so what I did was do this:
MusicTxt.text = "" + MusicSlider.value * 100;
Now my question is, can I make it a whole number instead of the decimals on the end, if so how?
Answer by HarshadK · Jan 13, 2015 at 01:06 PM
There are two ways:
1) You can directly set the values to be integer for the slider by checking the 'Whole Numbers' checkbox and then setting the min and max values to be 0 and 100. This will allow to choose values that are only integer values between 0 and 100 so you do not need to multiply the slider value by 100.
2) With your current code:
MusicTxt.text = "" + (int) MusicSlider.value * 100;
I need the slider it self to go from 0 - 1 because it has to control the audio and that only ranges from 0 - 1. So basically I am just wondering if its possible to get rid of the decimal points in the code.
Then use the method number 2. It will print values as integers and not float.
Just need to add brackets as below:
$$anonymous$$usicTxt.text = "" + (int) ($$anonymous$$usicSlider.value * 100);