VB6怎么将比值化简?
VB6怎么将比值化简?例如:321.47582325:485.725 化简后是几比几啊?
[此贴子已经被作者于2022-12-17 13:59编辑过]
Function ratio(x, y) As String Dim r&, a, b, lx&, ly&, gcd& If InStr(x, ".") > 0 Then lx = Len(Split(x, ".")(1)) If InStr(y, ".") > 0 Then ly = Len(Split(y, ".")(1)) If lx < ly Then lx = ly a = x * 10 ^ lx b = y * 10 ^ lx r = a - Int(a / b) * b While r a = b b = r r = a - Int(a / b) * b Wend gcd = b ratio = x & ":" & y & "=" & (x * 10 ^ lx) / gcd & ":" & (y * 10 ^ lx) / gcd End Function Sub test() a = 1234567.89 b = 12.3456 Debug.Print ratio(a, b) End Sub