Exemplo n.º 1
0
        //TODO Switch to latest versions of .NET and implement a BigInt Version.

        /// <summary>
        /// Rounds the given value to the specified number of significant figures/digits.
        /// </summary>
        /// <param name="val"> The value to be rounded </param>
        /// <param name="digits"> the number of significant figures </param>
        /// <returns> the rounded number </returns>
        public static double RoundToSignificantDigits(double val, int digits)
        {
            if (val == 0)
            {
                return(0);
            }

            double scale = QMath.Pow(10, QMath.Floor(QMath.Log10(QMath.Abs(val))) + 1);

            return(scale * QMath.Round(val / scale, digits));
        }