我正在使用Visual Basic的SSRS中使用自定义代码功能,下面我使用此代码将小数转换为小数,这也给了我一个混合数。因此,我想将其更改为不正确的分数。有什么建议吗?
***Public Function Dec2Frac(ByVal f As Double) As String
Dim df As Double
Dim lUpperPart As Long
Dim lLowerPart As Long
lUpperPart = 1
lLowerPart = 1
df = lUpperPart / lLowerPart
While (df <> f)
If (df < f) Then
lUpperPart = lUpperPart + 1
Else
lLowerPart = lLowerPart + 1
lUpperPart = f * lLowerPart
End If
df = lUpperPart / lLowerPart
End While
Dec2Frac =Cstr(lUpperPart\lLowerPart) & " " & CStr(lUpperPart mod lLowerPart) & "/" & CStr(lLowerPart***
答案 0 :(得分:1)
您只需要更改最后一行即可使用lUpperPart
。
Dec2Frac = CStr(lUpperPart) & "/" & CStr(lLowerPart)
结果:
1.875 = 15/8