Okay basically I have a class that manages sound and it's volume is a floating point value with 1.00f being 100% and 0.00f being 0%. So the math is done in low values. Allowing more precise calculations. Anyways, I'm adding and subtracting from the value by 0.05f as per the user's input. Well my problem is when it's at 1.00f and I subtract 0.05f from it it becomes 0.94f instead of 0.95f like it should. For the visual output I'm displaying an integer representation multiplied by 100 of the value.
if (Input.IsLeft())
{
if (MusicVolume > 0f && SelectedIndex == 0)
MusicVolume -= 0.05f;
if (MusicVolume < 0)
MusicVolume = 0;
}
if (Input.IsRight())
{
if (MusicVolume < 1f && SelectedIndex == 0)
MusicVolume += 0.05f;
if (MusicVolume > 1)
MusicVolume = 1;
}
MusicVolumeString = ((int)(MusicVolume * 100).ToString() + " %";
When subtracting from 1.00f it goes to 0.94f instead of 0.95f and when coming up from 0 it goes to 0.05 instead 0.06 like I would expect it to since it's dropping from 1.00 to 0.94. Any help on this is appreciated.
Thanks,
Jamie