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;
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;
You should use
Math.Round
MidpointRounding
Basically the function above will take your inputvalue and round it to 2 (or whichever number you specify) decimal places. With
MidpointRounding.AwayFromZero
when a number is halfway between two others, it is rounded toward the nearest number that is away from zero. There is also another option you can use that rounds towards the nearest even number.Use Math.Round
This works:
Another easy way is to use ToString with a parameter. Example:
Result:
you can try one from below.there are many way for this.