public static string ToSimplestForm(this float val) { bool hasDecimal = !val.AboutEqual(Mathf.Round(val)); string format = hasDecimal ? "{0:n1}" : "{0:n0}"; return(string.Format(format, val)); }
/// <summary> /// Calculates the moment of inertia of a solid sphere (ball). /// </summary> /// <remarks> /// <code> /// => I = 2mr² ÷ 5 /// </code> /// </remarks> /// <param name="m"></param> /// <param name="r"></param> /// <returns></returns> public static float MomentInertia(float m, float r = 1) { return(.4f * m * (r.AboutEqual(1) ? 1 : Mathf.Pow(r, 2))); }