Sora - 11 months ago 79

Vb.net Question

I have this number :

`666872700`

`666900000`

I used :

`Math.Round(666872700,4)`

Is there any easy way in vb.net I can use other than dividing by

`100000`

`100000`

Answer

The documentation for `Math.Round`

clearly states:

Rounds a double-precision floating-point value to a specified number of

fractional digits.

So it rounds stuff behind the decimal separator, but not integral part. I know of no other way than dividing, rounding and then multiplying again.

If you know a little C#, you can use the following extension method Jason Larke wrote in his answer to this question. I don't know whether it works, but you should be able to translate it to VB.NET and try it:

```
public static class MathExtensions
{
public static int Round(this int i, int nearest)
{
if (nearest <= 0 || nearest % 10 != 0)
throw new ArgumentOutOfRangeException("nearest", "Must round to a positive multiple of 10");
return (i + 5 * nearest / 10) / nearest * nearest;
}
}
```

Source (Stackoverflow)