- Home /
Convert float in Transform to double
Hello, everyone I know the transform property(position, rotation and scale) just uses float in Unity. However, I need double precision values in my project. So I wonder that if I convert the value from transform (float pecision) to double by myself, the extra digits in double values will be true or just some random numbers. Here is the code about what I said:
double x, y, z;
x = transform.position.x; //convert float to double
y = transform.position.y;
z = transform.position.z;
My English is not good. I hope I expressd it clearly. Thanks in advance!
Answer by vbs · Jul 19, 2017 at 02:43 PM
The extra digits won't be random, they will just be 0's, since you're adding more 0's to fill the precision level, so you won't be gaining precision, but you would be able to make more precise calculations going forward. There is no "seamless" way to increase precision, you would have to manage your own double precision transforms separate from Unity's editor and translate back, usually, relative to Unity's 0,0,0 origin.
In code you'd do:
double x, y, z;
x = (double)transform.position.x; //convert float to double
y = (double)transform.position.y;
z = (double)transform.position.z;
Your answer
![](https://koobas.hobune.stream/wayback/20220612104805im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Convert double to float for Vector3 1 Answer
Vector3 using Doubles Instead of Floats 2 Answers
Vector3 constructor precision 1 Answer