当前位置: 动力学知识库 > 问答 > 编程问答 >

unity3d - Unity floating point precision when using Json strings

问题描述:

Im writing a program with Unity and I need to add GameObject.transform to a dictionary so I use this code....

Dictionary<string,object> dict=new Dictionary<string,object>();

dict["position"]=gameObject.transform.position;

Then later i convert the Dictionary to a Json string

string jsn=Json.Serialize(dict);

When you look at the jsn string, the position is converted to only one or two decimal places, this cause small numbers to be truncated to zero giving me lots of headache.

Is there a way to tell Json to increase the number of decimal places it uses when converting floating point to a Json string?

Thanks Very much!

网友答案:

Json format badly works with a float numbers. Create your own class to work with vectors, where the double type is used, and convert it to json. Good luck!

分享给朋友:
您可能感兴趣的文章:
随机阅读: