' 将一个正数除以 y 返回一个整数或分数
Function RFs(ByVal x As Integer) As String
    If x = 0 Then
        RFs = 0
        Exit Function
    End If

    Dim div_result, div_remain, y, i As Integer
    y = 144
    div_result = x \ y
    div_remain = x Mod y
    
    If div_remain = 0 Then
        RFs = x / y
        Exit Function
    Else
        Dim z As Integer
        If div_remain > y Then
            z = y
        Else
            z = div_remain
        End If
        
        For i = z To 2 Step -1
            If div_remain Mod i = 0 And y Mod i = 0 Then
                If div_result > 0 Then
                    RFs = div_result & " + " & div_remain / i & "/" & y / i
                Else
                    RFs = div_remain / i & "/" & y / i
                End If
                Exit Function
            End If
        Next i
        If div_result > 0 Then
            RFs = div_result & " + " & div_remain & "/" & y
        Else
            RFs = div_remain & "/" & y
        End If
    End If
End Function

 

可以直接在 Excel 宏里面用 VBA 语言调用 比如 290 会得到 2 + 1/72

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2021-11-25
  • 2021-04-16
  • 2021-12-27
  • 2021-09-04
猜你喜欢
  • 2022-01-21
  • 2021-10-14
  • 2022-03-09
  • 2021-12-31
  • 2021-07-06
相关资源
相似解决方案