string to float with f

So i have the following code (all is in C#)

BTW: the xposs is recieved from a server so i cant just say its a float, i need it converted to a float with 0.0f behind:

xposs = "951.9791"

xspawn = float.Parse(yposs);

this just returns 951.9791 in a float but i want 951.9791f

i have also tried:

    xposs = "951.9791"
    
    xspawn = float.Parse(yposs) + 0.0f;

this still does not work.

I need it to be 0.0f format becaouse i use it in a Vector3(), and not having the f does not seem to work (well it works but the cordinates are totally wrong, and if i manually press f after it works.)

A float can’t be 951.9791f, it can only be 951.9791. You only add the “f” in a script to tell the compiler that it’s a float, but once compiled the number itself does not and cannot contain any letters. float.Parse is correct and returns a float, but your problem seems to be that you are using “xspawn = float.Parse(yposs);” when you should presumably be using “xspawn = float.Parse(xposs);”.

No idea if that works, just a spontaneous idea…

xposs = xposs + "f";

xspawn = float.Parse(xposs);

Edit: Nope, doesn’t work.

Another edit:

Your code works here. No need for an f…

private string xposs = "951.9791";

private float xspawn;

void Start () {
	xspawn = float.Parse(xposs);
	print(xspawn);
	transform.position = Vector3.zero * xspawn;
}

Floats are just a numeric value with type System.Float. They don’t have an f behind it. That’s just the notation C# uses for float literals. float.Parse returns a float, it’s not possible or necessary to add an f.
http://stackoverflow.com/questions/14166089/c-sharp-string-to-float-with-f