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
i
Use Math.Round
value = Math.Round(48.485, 2);
Use an interpolated string, this generates a rounded up string:
var strlen = 6;
$"{48.485:F2}"
Output
"48.49"
Math.Round(inputValue, 2, MidpointRounding.AwayFromZero)
I think all these answers are missing the question. The problem was to "Round UP", not just "Round". It is my understanding that Round Up means that ANY fractional value about a whole digit rounds up to the next WHOLE digit. ie: 48.0000000 = 48 but 25.00001 = 26. Is this not the definition of rounding up? (or have my past 60 years in accounting been misplaced?
Another easy way is to use ToString with a parameter. Example:
float d = 54.9700F;
string s = d.ToString("N2");
Console.WriteLine(s);
Result:
54.97
This works:
inputValue = Math.Round(inputValue, 2);