High-precision Integer Division
Private Sub commandementclick ()
Devide 123456789,987 654321, 2000
End Sub
Sub Devide (ByVal X As Long, ByVal Y As Long, Optional ByVal Numdigitsafterdecimal As Integer = 100, Optional ByRef result As String) 'x/y: Numdigitsafterdecimal (100 by default)
Dim a () As String, temp As Double, temp2 As Long, I As Integer
ReDim a (Numdigitsafterdecimal)
A (0) = X & "percent" & Y & "=" & Int (X/Y )&"."
Temp = X-(X/Y) * Y
For I = 1 To Numdigitsafterdecimal
Temp = temp * 10
Temp2 = Int (temp/Y)
A (I) = Right (temp2, 1)
Temp = temp-Int (temp/Y) * Y
Next
Result = Join (,"")
Debug. Print result
End Sub
Return Value:
123456789 bytes 987654321 = 0.1249999988609375000142382812498220214843772247314452846908569339413642883257329463959283381700508957728743638028390704524645116193441936047581975799405225302507434683718657066453516786669331040166633361997917082975026036462812174544214847818197314402272533569971593330375355083370308061457871149231776610634602792367067465095411656686307354291421158071357235524108034555948649568050641880399366976495007912793812401090077344986374033187670324585154120942685573488216430331397294620857533817239280827284508989658943637629263204529634209943379572375707755345303653058183704336772703695790341203802620734952467240813094159489836323006377045962420286925469746413431628169832104647877098691901536266351230796670609615041617379811979782752350252715595621841055054726986811815912664852301091689346236353883172045576460349430294245632121321929598483475880018956551499763043106252961961171837975485352025306433099683669586253954130171825573372852180332839347745839508153177006148085287423148933907210638326159
8670209230016622384624792220192190097247597623784405029702694937128716313285891046083926361923950920475950613494050617331324367283358445408958019432388024757095149690536310628868296117139146298535760671268302991609146212604885672342438929095719513386303506082671206173966609922825417375964682282800441471464994481606687568979916405387751044932653111938341836100770727048740365911890745426101365682173732928972828338387839645770152004427873099944651586250691855171866351810351670602370604117470367448531620406893354744913833065688577086678892786416513840169793576997877580287526530246405918371919926020351000924745612488440679843894491501951318856225608514297179893571285251330358934358370513320520368583493495392706331307591170858655110364266811120446664860994416689237569791384530377607693370279903832871501202089106234973886172062826422849214669714384816628570189792142872627598214092155022323848062220951899222238101259722023734253474703321831566208477105422394036182220074547722249068153471886648