1

I want to round 54.5345 to 54.54 that is if I have a third decimal place then i want to add 1 to the 2nd decimal place.

I have tried using math.round but it always rounds down if the third decimal is less than 5

Sabareesh Kkanan
  • 1,201
  • 1
  • 14
  • 22

2 Answers2

4

try:

d = Math.Ceiling(d * 100) / 100;

where d is your decimal.

borkovski
  • 938
  • 8
  • 12
0

I think you should try this:

      double a = Math.Round(-57.5345, 2); 

This works for negative numbers too.

The way you are rounding off is not correct.

You can also refer:

How do you round a number to two decimal places in C#?

Community
  • 1
  • 1
Dev
  • 1,451
  • 20
  • 30
  • Possible duplication of http://stackoverflow.com/questions/15643280/rounding-bigdecimal-to-always-have-two-decimal-places?rq=1 – Dev Oct 09 '13 at 23:17
  • please read the question again, I want to always round up the 2nd decimal if third decimal place exist – Sabareesh Kkanan Oct 10 '13 at 14:06