# i like to round a double to 2 decimal. • ### Question

• i like to round a value i am getting out off a calculation , for example 2,33333333333

i like to round this to 2 decimal 2,34

what is the way to do this?

data type = double.

Wednesday, May 2, 2012 1:03 PM

• You can use Math.Round(double, digits) http://msdn.microsoft.com/en-us/library/aa340228.aspx but 2,33... will be (correctly) approximated to 2.33, not to 2.34.

Matteo Migliore

Bloghttp://blogs.ugidotnet.org/matteomigliore
CodePlex

Wednesday, May 2, 2012 1:17 PM
• Matteo is right, but if you really want to obtain 2.34 (i.e., to round in any case to the greatest decimal), you can use this simple method:

```public double Round(double number, double arr)
{
double n = number / arr;
n = Math.Ceiling(n);

return (double)n* arr;
}

var number = 2.33333333333;
var rounded = Round(number, 0.01);  // Returns 2.34    ```

Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom

Wednesday, May 2, 2012 1:29 PM

### All replies

• You can use Math.Round(double, digits) http://msdn.microsoft.com/en-us/library/aa340228.aspx but 2,33... will be (correctly) approximated to 2.33, not to 2.34.

Matteo Migliore

Bloghttp://blogs.ugidotnet.org/matteomigliore
CodePlex

Wednesday, May 2, 2012 1:17 PM
• Matteo is right, but if you really want to obtain 2.34 (i.e., to round in any case to the greatest decimal), you can use this simple method:

```public double Round(double number, double arr)
{
double n = number / arr;
n = Math.Ceiling(n);

return (double)n* arr;
}

var number = 2.33333333333;
var rounded = Round(number, 0.01);  // Returns 2.34    ```

Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom