```
Function Roundsig(ynumber As Variant, xdirection As Variant, sig_amount As Variant, allow_decimals As Variant) As Double
Dim n As Integer, x As Double
Dim xnumber As Variant
If xdirection = 0 Xor xdirection = 1 Xor xdirection = -1 Then
If sig_amount < 1 Or sig_amount <> Int(sig_amount) Then
Roundsig = CVErr(xlErrNA)
ElseIf allow_decimals <> 0 And allow_decimals <> 1 Then
Roundsig = CVErr(xlErrNA)
Else
xnumber = Abs(ynumber)
xsign = Sgn(ynumber)
If xnumber >= 1 Then
x = xnumber
n = 0
While x > 1
x = x / 10
n = n + 1
Wend
' x = x * 10 ^ sig_amount
x = xnumber * 10 ^ (sig_amount - n)
If xdirection = -1 Then
x = Int(x)
ElseIf xdirection = 0 Then
x = Int(x + 0.5)
ElseIf x = Int(x) Then
x = Int(x)
ElseIf x <> Int(x) Then
x = Int(x) + 1
End If
x = x * 10 ^ (n - sig_amount)
If allow_decimals = 0 Then
' If xdirection = -1 Then
' x = Int(x)
' ElseIf xdirection = 0 Then
x = Int(x + 0.5)
' ElseIf x <> Int(x) Then
' x = Int(x) + 1
' End If
End If
Else
x = xnumber
n = 0
While x < 0.1
x = x * 10
n = n - 1
Wend
x = x * 10 ^ sig_amount
If xdirection = -1 Then
x = Int(x)
ElseIf xdirection = 0 Then
x = Int(x + 0.5)
ElseIf x <> Int(x) Then
x = Int(x) + 1
End If
x = x * 10 ^ (n - sig_amount)
If allow_decimals = 0 Then
' If xdirection = -1 Then
' x = Int(x)
' ElseIf xdirection = 0 Then
x = Int(x + 0.5)
' ElseIf x <> Int(x) Then
' x = Int(x) + 1
' End If
End If
End If
x = x * xsign
Roundsig = x
End If
Else
Roundsig = CVErr(xlErrNA)
End If
End Function
```