tags:

views:

612

answers:

3

I want to round up double value in two decimal places in c# how can i do that?

double inputValue = 48.485;

after round up

inputValue = 48.49;

+4  A: 

Use Math.Round

value = Math.Round(48.485, 2);
recursive
Beat me to it (although I'd add a semi-colon on there, too ;) )
Reed Copsey
However, be careful with MidpointRounding: "If the value of the first digit in value to the right of the digits decimal position is 5, the digit in the digits position is rounded up if it is odd, or left unchanged if it is even"
winSharp93
+4  A: 

This work:

inputValue = Math.Round(inputValue, 2);
Alex LE
+3  A: 
Math.Round(inputValue, 2, MidpointRounding.AwayFromZero)
Ding
This is actually what should be used. Most operations in banks etc are done using this method (MidpointRounding.AwayFromZero).
MadBoy