rounds a decimal value to even, the number of decimal places indicated in the parameters - CSharp System

CSharp examples for System:Math Number

Description

rounds a decimal value to even, the number of decimal places indicated in the parameters

Demo Code

/* *******************************************************************************
 * Copyright (c) 2005-2012 Zibler S de RL MI.
 * //from w w w.  j  a  v a  2 s  .c o m
 * This file is part of Zibler.
 * 
 * Zibler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Zibler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Zibler.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * *******************************************************************************/
using System.Threading;
using System.Text;
using System.Security.Cryptography;
using System;

public class Main{
        /// <summary>
        /// This function rounds a decimal value to even, the number of decimal places
        /// indicated in the parameters
        /// </summary>
        /// <remarks>
        /// When a number is between two others, it is rounded towards the nearest even number.
        /// </remarks>
        /// <param name="number">Number to round</param>
        /// <param name="decimalPlaces">Decimal places to round (precision)</param>
        /// <returns>Rounded value</returns>
        public static decimal RoundToEven (decimal number, int decimalPlaces)
        {
            decimal result = System.Math.Round(number, decimalPlaces, MidpointRounding.ToEven);

            return result;
        }
}

Related Tutorials