VB6.0自定义函数求助
FunctionSSWR(xAsString,nAsInteger)AsDoubleIfMid(x,InStr(x,".")+n,1)>=5Thenx=Left(x,In...
Function SSWR(x As String, n As Integer) As Double
If Mid(x, InStr(x, ".") + n, 1) >= 5 Then
x = Left(x, InStr(x, ".") + n - 1) + (1 / (1 * 10 ^ (n - 1)))
Else
x = Left(x, InStr(x, ".") + n - 1)
End If
End Function
写的个自定义函数对小数进行四舍五入,不知道对不对,x代表小数,n表示保留位数
但是在调用时弹出来的怎么是0,不知道怎么回事,求高手解答?? 展开
If Mid(x, InStr(x, ".") + n, 1) >= 5 Then
x = Left(x, InStr(x, ".") + n - 1) + (1 / (1 * 10 ^ (n - 1)))
Else
x = Left(x, InStr(x, ".") + n - 1)
End If
End Function
写的个自定义函数对小数进行四舍五入,不知道对不对,x代表小数,n表示保留位数
但是在调用时弹出来的怎么是0,不知道怎么回事,求高手解答?? 展开
2个回答
展开全部
Private Sub Form_Load()
MsgBox SSWR("1.123456", 6)
End Sub
Function SSWR(x As String, n As Integer) As Double
If Mid(x, InStr(x, ".") + n, 1) >= 5 Then
x = Left(x, InStr(x, ".") + n - 1) + (1 / (1 * 10 ^ (n - 1)))
Else
x = Left(x, InStr(x, ".") + n)
End If
SSWR = x
End Function
MsgBox SSWR("1.123456", 6)
End Sub
Function SSWR(x As String, n As Integer) As Double
If Mid(x, InStr(x, ".") + n, 1) >= 5 Then
x = Left(x, InStr(x, ".") + n - 1) + (1 / (1 * 10 ^ (n - 1)))
Else
x = Left(x, InStr(x, ".") + n)
End If
SSWR = x
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询