- Home /
Float.Parse() Question (Quickie)
Hello, all! I have a string like this:
"0.123"
and I used:
Debug.Log(float.Parse(MyString));
On it and got an output of 0.1 as opposed to the entire float. What's going on? Am I using an improper function?
Thanks!- YA
Answer by Bunny83 · Aug 20, 2012 at 07:54 PM
I'm not sure what you're doing wrong. When i use:
Debug.Log(float.Parse("0.123"));
Unity prints : "0.123"
Maybe you talk about the values in a struct like Vector3? Unity rounds the values when you convert them to a string, but the actual value is correct.
$$anonymous$$aybe I should give you more info. Firstly, it is actually several floats like this : "0.1234.3245.324" Each having 4 decimal places. So it is actually Debug.Log(float.Parse($$anonymous$$yString.Substring(0,5)));
Which now gives me:
0.22
What's up?
And also, I A$$anonymous$$ converting to string at some point. Is there a way I can prevent rounding to a certain point?
Thanks for the help! - YA
I think I have figures it out. I am debug.logg'ing a COLOR. Wow. I'm a little embarrassed over here. Well thanks for the help!- YA
Is there really no seperator between your 3 values? How can you tell where a number starts and where it ends? What is a value has two digits before the decimal point?
Ah well I borrowed a color picker code from the community and have it in game. I made my own picker in photoshop and when I debugged the code, it exported R,G,B, and A floats that were all in a format of:
X.XXX
Will it not always be this way? I can easily right code to have a separator there.