ToString ("f0") is rounding my float
Say my number is at 1.6, well my tostring text on screen is showing 2. I don't want it to do that, I only want it to show 1, then when it hits 2 or 2.1 , the text will show 2. To explain a little more, please check my comment below I hope that kinda explains why it's frustrating that it's round my numbers on screen when the number is still lower
That's what "F0" is supposed to do. It's regular C#, so you can look up examples.
It would help in the future if you wrote the exact line of code.
public float number;
public Text numberText;
public void Start(){
numberText.text = number.ToString('f0");
}
That's not the actual code, but example of it. I've tried ("n"), ("0"), and plenty of other things. If I put ("f1") then it keeps my 1 at one till it reaches 2, but shows a decimal. If I use ('f0") then once it hits 1.5, it changes the text to 2. Is there a way around this ?
Use Split:
string[] array = number.ToString().Split(new char[]
{
'.'
});
numberText.text = array[0].PadLeft(1, '0');
Answer by jgodfrey · Mar 13, 2016 at 03:34 PM
Sounds like you want:
Mathf.Floor(number).ToText();
"Returns the largest integer smaller to or equal to f" That is exactly what I need, thank you so much !!