现在的位置: 首页 > 综合 > 正文

除法方法

2013年07月29日 ⁄ 综合 ⁄ 共 776字 ⁄ 字号 评论关闭

使用以下原创代码请遵循协议.

 

Div()

Protected Function div(ByVal a As IntegerByVal b As IntegerAs String
    
Dim s As String = ""

    If a < b Then
        s 
= "0."
        a 
= a * 10
    
Else
        s 
= Int(a / b).ToString() & "."
        a 
= a - Int(a / b) * b
        a 
= a * 10
    
End If

    Dim l As New List(Of Integer)

    While Not l.Contains(a)
        
If Int(a / b) = 0 Then
            a 
= a * 10
            s 
&= "0"
        
Else
            l.Add(a)
            s 
&= Int(a / b).ToString()
            a 
= a - Int(a / b) * b
            a 
= a * 10
            
If a = 0 Then
                
Return s
            
End If
        
End If

    End While

    For i As Integer = 0 To l.Count - 1
        
If a = l(i) Then
            s 
= s.Insert(i + 2"[")
        
End If
    
Next

    Return s & "]"
End Function

 

抱歉!评论已关闭.