Visual Basic Programming Code Examples Visual Basic > Other Code Examples Rounds your numbers to specified decimals Rounds your numbers to specified decimals I was looking at the function rounding. Once I had to make a Round-function and I made exactly the same function as you showed on your VB-page. But this one isn't working properly. (reference: VB 09-05-97) See the example below: Round(2.15,1) = 2.2 OK Round(1.15,1) = 1.1 Not OK The type declaration of the parameter X should be changed from Double to Variant. Function Round (X as Variant, DP as integer) as Double Round = Int((X * 10 ^ DP) + 0.5) / 10 ^ DP End Function Use the following: Function Round (X as Double, DP as integer) as Double Round = Int((X * 10 ^ DP) + 0.5) / 10 ^ DP End Function where DP is the decimal place to round to (0 to 14) e.g Round (3.56376, 3) will give the result 3.564 Round (3.56376, 1) will give the result 3.6 Round (3.56376, 0) will give the result 4 Round (3.56376, 2) will give the result 3.56 Round (1.4999, 3) will give the result 1.5 Round (1.4899, 2) will give the result 1.49 How to round a number to the nearest value of 5. 12.4 + 2.5 = 14.9 \5 = 2 * 5 = 10 12.6 + 2.5 = 15.1\5 = 3 * 5 = 15 18.1 + 2.5 = 20.6\5 = 4 * 5 =20 Note the case of 12.5 (12.5 + 2.5 = 15\5 = 3 * 5 = 15). This rounds up from the midpoint. If you want to round down at the midpoint, you might have to use 2.49 or 2.499 etc depending on the precision of your data. Return