 # Thread: Equivalent of Round Function in Xbasic?

1. ## Equivalent of Round Function in Xbasic?

Here is a round function created in visual basic. How do we do this in Xbasic?Thanks!

Public Function RoundExt( _
ByVal dblNumber As Double, _
ByVal intDecimals As Integer) _
As Double
' Comments : Rounds a number to a specified number of decimal
' places (0.5 is rounded up). Unlike the VB 6 Round
' function, this one works correctly.
' Parameters: dblNumber - number to round
' intDecimals - number of decimal places to round to
' (positive for right of decimal, negative for left)
' Returns : Rounded number
'

Dim dblFactor As Double
Dim dblTemp As Double

On Error GoTo PROC_ERR

dblFactor = 10 ^ intDecimals
dblTemp = dblNumber * dblFactor + 0.5
RoundExt = Int(CDec(dblTemp)) / dblFactor

PROC_EXIT:
Exit Function

PROC_ERR:
MsgBox "Error: " & err.Number & ". " & err.Description, , _
"RoundExt"
Resume PROC_EXIT

End Function  Reply With Quote

2. ## Re: Equivalent of Round Function in Xbasic?

Are you sayiing Alpha's round function is flawed?

http://wiki.alphasoftware.com/ROUND+Function  Reply With Quote

3. ## Re: Equivalent of Round Function in Xbasic?

I think without looking up:

Round()
round_down()
round_up()

They are already written for you.
If you go back to v7, round down did not work so I rewrote it and it is in the code archive.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•