 # Round Up to next highest whole number

How can I RoundUp the rectangle to the nearest whole number? So when a rectangle that is an odd size i.e. 40.1"w x 12.135"h, it'll Round to 41 & 13.

________________________________

dLeeway = 0.5

sr.Add ActiveLayer.CreateRectangle2(x - dLeeway, y - dLeeway, w + dLeeway * 2, h + dLeeway * 2)

• use  Round(w + 0.5, 0)

• Usually if you want to round up from x.5 you add 0.5 to the dimension. In this case add 0.999 to the dimension

dLeeway = 0.5

FinalWidth = int(w + dLeeway * 2 + 0.999)

FinalHeight = int(h + dLeeway * 2 + 0.999)

sr.Add ActiveLayer.CreateRectangle2(x - dLeeway, y - dLeeway, FinalWidth, FinalHeight)

• I think that shark_ has shown a good way to do this.

Round is a VBA function, so you can look it up online to find more details if you wish.

You supply that function with an expression (the value that you want to round). In shark_'s example, that expression is w + 0.5.

You can also (optionally) specify the number of decimal places to be used when rounding. In the example given, that is 0 (no decimal places).

The function "returns" the result of rounding the value of the expression to the specified number of decimal places.

If you wanted to use the value of w, but rounded up to the next integer using shark_'s approach, where you now have w in your code, you would instead have Round(w + 0.5, 0).

The Round function uses something called "banker's rounding", which is different from the way that many of us were taught in school to round numbers. The addition of 0.5 has been added to get it to always "round up".

For use in my many macros, I have my own rounding function that does the rounding the way that I was taught in school, rather than following "banker's rounding" rules.

I also have my own "round up" function that rounds up to a specified number of decimal places:

```Function JQ_RoundUp(Number As Double, NumDecPl As Long) As Double

Dim dblTemp As Double

On Error GoTo ErrHandler

dblTemp = Number * 10 ^ NumDecPl
If dblTemp > Int(dblTemp) Then
JQ_RoundUp = (Int(dblTemp) + 1) / 10 ^ NumDecPl
Else
JQ_RoundUp = Number
End If

ExitFunc:
Exit Function

ErrHandler:
MsgBox "Error occurred: " & Err.Description & vbCrLf & vbCrLf & "JQ_RoundUp()"
Resume ExitFunc
End Function
```

You could use that function for your "rounding up" job.