C# Decimal Round(Decimal, Int32)

Description

Decimal Round(Decimal, Int32) rounds a Decimal value to a specified number of decimal places.

Syntax

Decimal.Round(Decimal, Int32) has the following syntax.


public static decimal Round(
  decimal d,
  int decimals
)

Parameters

Decimal.Round(Decimal, Int32) has the following parameters.

  • d - A decimal number to round.
  • decimals - A value from 0 to 28 that specifies the number of decimal places to round to.

Returns

Decimal.Round(Decimal, Int32) method returns The decimal number equivalent to d rounded to decimals number of decimal places.

Example

Example of the decimal.Round method.


/* w  w w .  j  a v  a 2  s.co m*/
using System;

class DecimalRoundDemo
{
    public static void Main( )
    {
        decimal rounded = decimal.Round( 1.45M, 1 );

        Console.WriteLine( rounded );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version