Reputation: 325
I have double number and i want to approximate it always to the nearest .
for eg: 1.2324 -> 1 1.898 -> 2
how can i do this with C#?
Upvotes: 2
Views: 4797
Reputation: 361692
Use Math.Round()
.
double d1 = Math.Round(1.2324); //d1 is 1
double d2 = Math.Round(1.898); //d2 is 2
Upvotes: 3
Reputation: 384
Math.Round(double)
does the trick. If you want to use a variable number of decimals behind the decimal point you can use Math.Round(double, int)
The API describing this is here.
Upvotes: 0
Reputation: 973
Try Math.Round http://msdn.microsoft.com/en-us/library/aa340225(v=vs.71).aspx
Upvotes: 0