Round a Decimal value to a specified number of decimal places in CSharp

Description

The following code shows how to round a Decimal value to a specified number of decimal places.

Example


/* ww w .  j  a  v  a 2  s .  c  om*/
using System;

class MainClass
{
    
    public static void ShowDecimalRound( decimal Argument, int Digits )
    {
        decimal rounded = decimal.Round( Argument, Digits );
        Console.WriteLine( "{0,26}{1,8}{2,26}", Argument, Digits, rounded );
    }

    public static void Main( )
    {

        ShowDecimalRound( 1.45M, 1 );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var