Big numbers are magically transformed if entered in Inspector

Inside my script of a certain game object I define a public variable as double.

public double V;

In the Inspector I define its value as 5e+18.

Inside Awake() I put some lines to test this value:

Debug.Log("My number = " + V);

Why, even if I strictly defined variable as double, my output looks like this:

My number = 4.99999999025322E+18


I made one more test. Now I have defined my variable not in the Inspector window, but inside my script. After that I get an output as it should be - showing My number = 5e+18.

So it appears that Unity still translates values defined via Inspector as floats.

Is it normal behavior of Unity3d (3.5.5f2)??

Definitely looks like a bug. IEEE-754 states that even a float should be able to hold 5e18.

I think that it related with Numerical Instability, it is not a bug. Basically, there is no way to have any number representation in 32 bits, a number lose its precision when start to get near of their bounds. Further explanation:

Take a look on this script it it solve your problem:

So I went to test a little further and weirdly I do not get exactly the same behaviors:

Simple program:

var dbInsp:double;  // Put in the inspector
var str:String = "5e+18";
var db:double = 5e+18;
var strToDb:double;
double.TryParse(str, strToDb);

print("Str:"+str) ;



I even get wrong when giving from the script. On the other hand, the conversion from string to double works fine.
I tried with lower and cap e but it does not matter.

So, I think that could be a bug.