-6

I want to get the round off value of a decimal number Suppose I am getting 24.86 than i want to get 25 as final value

James
  • 162
  • 1
  • 10

2 Answers2

1

Look at Math.Round(decimal) and the overload which accepts a MidpointRounding argument.

Anton Gogolev
  • 110,157
  • 37
  • 194
  • 282
0

Simply

Math.Round(24.86)

This will round you value to 25.

Your own logic will be

decimal d = 1.5m;
decimal r = d - Math.Truncate(d);

if (r > 0)
     r = 1 - r;

decimal value = d + r;
Nikhil Agrawal
  • 44,717
  • 22
  • 115
  • 201