我有这个功能,它可以工作,除了显示英寸11.25而不显示11。
Function InchesToFtIn(varInches As Variant) As String
Dim intFeet As Integer
Dim intInch1 As Integer
Dim intInch2 As Single
Dim strReturn As String
strReturn = ""
intFeet = 0
intInch1 = 0
intInch2 = 0
intInch1 = Val(Nz(varInches, 0))
intFeet = intInch1 \ 12
intInch2 = ((intInch1 / 12) - intFeet) * 12
strReturn = intFeet & "'" & intInch2 & Chr(34)
InchesToFtIn = strReturn
End Function
任何人都知道我做错了什么?
答案 0 :(得分:0)
更改
intInch2 = ((intInch1 / 12) - intFeet) * 12
到
intInch2 = intInch1 - (intFeet * 12)
答案 1 :(得分:0)
您可以使用Mod
减少它:
Public Function InchesToFtIn(varInches As Variant) As String
Dim intInches As Integer
Dim strReturn As String
If IsNumeric(varInches) Then
intInches = Val(varInches)
strReturn = intInches \ 12 & "'" & intInches Mod 12 & """"
End If
InchesToFtIn = strReturn
End Function