15,748,049 members
See more:
How can i format the decimal variable??
Suppose,
I declare decimal type variable i = 0;
and i is 6.1056.
Actually I want to get the value is 6.11
how will i do above problem????
Posted

## Solution 1

Have a look at Math.Round [^]

C#
```decimal a = 1.994444M;
Math.Round(a, 2); //returns 1.99```

from http://stackoverflow.com/questions/257005/how-do-you-round-a-number-to-two-decimal-places-in-c[^]

Mohamed Mitwalli 23-May-12 8:38am
5+
Nilesh Patil Kolhapur 23-May-12 8:42am
my also 5+
VJ Reddy 23-May-12 9:45am

## Solution 2

Try this

C#
`i = Math.Round(6.1056,2);`

VJ Reddy 23-May-12 9:45am
My 5!

## Solution 3

As already given in Solution 1 and 2, the `Round` method of `Math `class explained here
Math.Round Method (Decimal, Int32, MidpointRounding)[^]
can be used as follows:
C#
```decimal number = 6.1056M;
Console.WriteLine (Math.Round(number,2));```

By default the `Round `method uses `MidpointRounding.ToEven` enumeration value explained here http://msdn.microsoft.com/en-us/library/system.midpointrounding.aspx[^], which means that if the value to be rounded is `6.105` it will be rounded off to `6.10` and if it is `6.115` then it will be rounded off to `6.12` as `5 `is the `mid point`.

If the `MidpointRounding.AwayFromZero `is used as shown below
C#
```decimal number = 6.1056M;
Console.WriteLine (Math.Round(number,2, MidpointRounding.AwayFromZero));```

then the above values will be rounded off to `6.11` and `6.12` respectively, i.e. always the number `away from zero`, in other words the `next higher number` will be taken.

Nelek 23-May-12 16:35pm
Nice explanation
VJ Reddy 23-May-12 20:46pm
Thank you, Nelek :)
Mohamed Mitwalli 23-May-12 17:15pm
5+
VJ Reddy 23-May-12 20:46pm
Thank you, Mohamed :)
Espen Harlinn 23-May-12 18:21pm
Informative :-D