Private Sub Form_Load() Dim a, b As Double Dim c As String a = 436.1 b = 0.045 a = FormatPoint(a) Debug.Print a c = FormatPoint(a*b) Debug.Print c End SubPrivate Function FormatPoint(ByVal pValue As Double) As String FormatPoint = Format(Mid(pValue, 1, InStr(1, pValue, ".") - 1), "0000") & Mid(pValue, InStr(1, pValue, "."), 2) End Function
强调 不能用 “0” & 436.1 和 “00”& 19.6***********************
Dim a, b As Double
Dim c As String
a = 436.1
b = 0.045
a = FormatPoint(a)
Debug.Print a
c = FormatPoint(a*b)
Debug.Print c
End SubPrivate Function FormatPoint(ByVal pValue As Double) As String
FormatPoint = Format(Mid(pValue, 1, InStr(1, pValue, ".") - 1), "0000") & Mid(pValue, InStr(1, pValue, "."), 2)
End Function