Vector3.Normalize returns is not accurate result

Hello community! Today i found strange “bug?” with Vector3 method normalize, that method in some cases returns is not accurate result and i don’t know why and how to fix it, please help.

you can see result in this PG


as workaround i wrote this:

const normalized = Vector3.Normalize(direction);
    return normalized;

You have encountered JS precision in its full force. the same os 0.1 + 0.2 :slight_smile:
You can round the results if you expect integers, of course. But this might not be exactly what you expect. If you want precision in floating points you could do something like this:

Math.round(num * 100) / 100

But this is a very naive approach :slight_smile:

1 Like

But why Normalize returns floats if its means that elements of vector3 must be strict equals 1? Or am i wrong?

normalization does not mean integers only. the vector (0.5, 0.5, 0.5) normalized is _0.5773502691896258, 0.5773502691896258, 0.5773502691896258

sorry - posted too soon. a normalized vector just means that its length is 1.

Oh now I understand, thank you for explanation :slightly_smiling_face: