High precision integer division

xiaoxiao2021-03-06  51

Private Sub Command1_Click () Devide 123456789, 987654321, 2000END SUB

Sub Devide (ByVal X As Long, ByVal Y As Long, Optional ByVal Numdigitsafterdecimal As Integer = 100, Optional ByRef result As String) 'x / y after the decimal point Numdigitsafterdecimal bits (default 100) Dim a () As String, temp As Double , TEMP2 As Long, I as IntederRedim A (NumdigitsAfterDecimal) A (0) = X & "÷" & Y & "=" & int (x / y) & "." TEMP = X - (x / y) * YFOR i = 1 to NumdigitsAfterDecimaltemp = Temp * 10Temp2 = int (TEMP / Y) A (i) = Right (Temp2, 1) Temp = Temp - INT (TEMP / Y) * YNEXTRESULT = JOIN (A, ") Debug.print Resultens Sub

return:

123456789 ÷ 987654321 =

0.12499999886093750001423828124982202148437722473144528469085693394136428832573294639592833817005089577287436380283907045246451161934419360475819757994052253025074346837186570664535167866693310401666333619979170829750260364628121745442148478181973144022725335699715933303753550833703080614578711492317766106346027923670674650954116566863073542914211580713572355241080345559486495680506418803993669764950079127938124010900773449863740331876703245851541209426855734882164303313972946208575338172392808272845089896589436376292632045296342099433795723757077553453036530581837043367727036957903412038026207349524672408130941594898363230063770459624202869254697464134316281698321046478770986919015362663512307966706096150416173798119797827523502527155956218410550547269868118159126648523010916893462363538831720455764603494302942456321213219295984834758800189565514997630431062529619611718379754853520253064330996836695862539541301718255733728521803328393477458395081531770061480852874231489339072106383261 598670209230016622384624792220192190097247597623784405029702694937128716313285891046083926361923950920475950613494050617331324367283358445408958019432388024757095149690536310628868296117139146298535760671268302991609146212604885672342438929095719513386303506082671206173966609922825417375964682282800441471464994481606687568979916405387751044932653111938341836100770727048740365911890745426101365682173732928972828338387839645770152004427873099944651586250691855171866351810351670602370604117470367448531620406893354744913833065688577086678892786416513840169793576997877580287526530246405918371919926020351000924745612488440679843894491501951318856225608514297179893571285251330358934358370513320520368583493495392706331307591170858655110364266811120

转载请注明原文地址:https://www.9cbs.com/read-116186.html

New Post(0)