Ejemplo n.º 1
0
        /// <summary>
        /// Rounds the given value to the specified number of decimal places.
        /// The value is rounded using the given method which is any method defined
        /// in <seealso cref="BigDecimal"/>.
        /// </summary>
        /// <param name="x"> Value to round. </param>
        /// <param name="scale"> Number of digits to the right of the decimal point. </param>
        /// <param name="roundingMethod"> Rounding method as defined in <seealso cref="BigDecimal"/>. </param>
        /// <returns> the rounded value.
        /// @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0) </returns>
        /// <exception cref="MathArithmeticException"> if an exact operation is required but result is not exact </exception>
        /// <exception cref="MathIllegalArgumentException"> if {@code roundingMethod} is not a valid rounding method. </exception>
        public static float Round(float x, int scale, int roundingMethod)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float sign = FastMath.copySign(1f, x);
            float sign = FastMath.CopySign(1f, x);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float factor = (float) FastMath.pow(10.0f, scale) * sign;
            float factor = (float)FastMath.pow(10.0f, scale) * sign;

            return((float)RoundUnscaled(x * factor, sign, roundingMethod) / factor);
        }