Parsing floats mac-PC

hello unity community!

I’ve got a small problem. I’ve created a small web application where users can edit a room and save all the locations of the objects in the room. When you load the application it will load that ASP and parse all the objects and instantiate them in the room.

now this was developped on pc, but due to circumstances I had to continue the development on mac and when I tried to run it, I noticed that the locations of my paintings didn’t parse well.

I think this is due to the fact that I use ParseFloat(string) to turn my splitted string into floats for my postion/quaternion. but I get really large numbers instead.

here’s a sample of what I parse

Future Flow ;2008;Jerre;3,135276;1,407117;-1,048797;-1,514731E-07;0;0;1$

with first the name, the year, the creator, the position x,y,z and quaternion x,y,z,w all seperated by ; and closed with a $

could it be the fact that my transform.position.x saves a comma float, while mac wants a .?

thanks in advance, first problem I’ve encountered with Unity, but that doesn’t change my positive opinion about it, as a Technical Artist, I just love it :stuck_out_tongue:

I don’t think thats an OS X / windows issue, but rather a internationalisation problem. More info here: c# - Best way to parse float? - Stack Overflow

thx for the reply, is there also a way to do this in javascript?

JavaScript in unity uses the .net API just like C# does. The syntax might need some changing here and there, but the classes, methods etc. are all the same.

Just for reference:

In Javascript do the following:

  1. Add the internationalization import:
import System.Globalization;
  1. Add these helpers to your code:
function ConvertVector3(str1 : String, str2 : String, str3 : String) {
	return Vector3(ConvertStringFloat(str1), ConvertStringFloat(str2), ConvertStringFloat(str3));
}

function ConvertQuaternion(str1 : String, str2 : String, str3 : String, str4 : String) {
	return Quaternion(ConvertStringFloat(str1), ConvertStringFloat(str2), ConvertStringFloat(str3), ConvertStringFloat(str4));
}

function ConvertStringFloat(str : String) {
	return float.Parse(str, CultureInfo.InvariantCulture);
}
  1. Convert a string with a Vector3 position like this:
var posBox : Vector3 = ConvertVector3(boxArray[0], boxArray[1], boxArray[2]);