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
Asked
Active
Viewed 265 times
-6
-
3Have you considered to search for `Round C#`? – Tim Schmelter Apr 04 '14 at 10:30
-
Why don't do a little search before asking?? [Decimal.Round](http://msdn.microsoft.com/en-us/library/system.decimal.round.aspx) – huMpty duMpty Apr 04 '14 at 10:31
-
yeah I know about Math.Round but i want to do it by my own logic – James Apr 04 '14 at 10:34
-
1@Ankit: Please edit your question with the logic you need to implement / why you don't need to use `Math.Round()`!! – huMpty duMpty Apr 04 '14 at 10:35
2 Answers
1
Look at Math.Round(decimal)
and the overload which accepts a MidpointRounding
argument.

Anton Gogolev
- 113,561
- 39
- 200
- 288
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
- 47,018
- 22
- 121
- 208