I want Unity's slider value to handle large numbers precisely (it only works in the format of "xxx e+X")

415 Views Asked by At

I've been using Unity's slider to handle large numbers, and it accepts them. The problem is that the value stored is in the format "xxx e+X" (for instance, 9.999998e+08), enter image description here so, if I wanted to subtract one to this value, or add one to it, it doesn't change the value (for instance, the OnValueChanged callback doesn't get called) as it is only sensitive to larger steps (like, for example, changes over 50-100 units/integers and above.

Is there a way to make the slider work with long integers (plain number format)?

Thank you.


What I tried:

The slider max value is set to 999999799 (ended in 799). Then it translates into "9.999998e+08". if I convert this float value (9.999998e+08) to "long", I get 999999800, probably because it doesn't take into account small figures and goes by larger steps.

The only way that occurs to me to get the correct "long" is to convert the "slider max value" to string (string stringValue = _mySlider.value.ToString("F0")) and then get the "long" (long longValue= Convert.ToInt64(stringValue)). This way, I get the expected long (999999799).

However, this is not suitable since I cannot convert this long value into the slider value. If I wanted to subtract one from the long value (longValue--; (999999798)) and then set the slider value to the long value: _mySlider.value = (float) longValue, the value of the slider doesn't change, it keeps being the same: 9.999998e+08. When translating the number, it yields 999999799 instead of 999999798. (Same happens if I did _mySlider.value--; directly)

I need the slider to handle large numbers too.

0

There are 0 best solutions below