There is no floating point encoding for exactly N decimal digits of precision. Use a decimal value if you want to.
If you need only 7-digit precision, then return a float that has exactly that.
public static float Distance(Vector3 v1, Vector3 v2)
{
return
(
(float)Math.Sqrt
(
(v1.X - v2.X) * (v1.X - v2.X) +
(v1.Y - v2.Y) * (v1.Y - v2.Y) +
(v1.Z - v2.Z) * (v1.Z - v2.Z)
)
);
}
If you want to display 7 digits of precision, then: result.ToString ("F7");
source
share