Possible Duplicate:
c# - How do I round a decimal value to 2 decimal places (for output on a page)
How to round decimal value up to nearest 0.05 value??, the linked SO post also discusses the similar topic, but its not the output i expected.
I need to convert the decimal values like this
16.489-->16.49
16.482-->16.48
16.425-->16.43
7.67 --> 7.67 (no conversion)
I can use the below C# method to convert the values
Math.Round(16.482*20)/20;
But this method not works for me, it gives the following results
16.489-->16.5
16.482-->16.5
7.67 --> 7.7
16.425-->16.45
whats the elegant way in c# to do this.
Math..::.Round Method (Decimal, Int32, MidpointRounding)
Rounds a double-precision floating-point value to the specified number of fractional digits. A parameter specifies how to round the value if it is midway between two other numbers.
Math.Round(1.489,2,MidpointRounding.AwayFromZero)
Did you try
Math.Round(16.482*200)/200;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With