I am using Unity’s slider to set a floating point number between the ranges of 1.0 - 10.0. The problem is, it rounds off. I do not want the slider to round off the value, instead it should display as it is. Can you please help me fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
private Slider sliderUI;
void Start () {
sliderUI = GetComponent<Slider> ();
sliderUI.value = 3.56f;
}
The slider value changes to 3.6. How do I make it 3.56?
Where exactly do you see the number “change” to 3.6? The slider does not round the values unless you set it to use “whole numbers” in which case the numbers are rounded to the next whole number. All the source code of the uGUI system is in Unity’s github repository. Here’s the Slider class. You will notice that it does not round any numbers unless “wholeNumbers” is set to true.
Maybe you view the value as part of a Vector3? Vector3 values are rounded to one decimal place when you use ToString without any arguments.
I would suggest you read what was asked again. In the very least, state how you are “seeing” the value rather than asking for a “fix”.
The dev above was essentially indicating that every single digit after the decimal point isn’t always displayed depending on how you’re viewing it. Visual Studio, the Unity Inspector, Debug.Log can all show approximate values, depending on what you’re viewing.