PowerBuilder Translate/Convert Money To String USD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | global type f_translate_to_english from function_object end type forward prototypes global function string f_translate_to_english (string as_money) end prototypes global function string f_translate_to_english (string as_money);// Function: f_translate_to_english // Input : number string // Output : character string // Using : translate number string to character string String result, tenrow, tenline, numberchar, threenumber, numberone String numbertwo, numberthree, translate, threechar String denary, hundreddenary Integer e, i, j, s, li_find, li_posdot Dec{2} ld_dec as_money = Trim(as_money) li_find = Pos(as_money, ",", 1) Do While li_find <> 0 as_money = Left(as_money, li_find - 1) + Right(as_money, Len(as_money) - li_find) li_find = Pos(as_money, ",", li_find + 1) Loop If Dec(as_money) = 0 Then result = 'ZERO USD' Return result End If li_posdot = Pos(as_money, '.') If li_posdot = 0 Then as_money = as_money + '.00' Else ld_dec = Round(Dec(Mid(as_money,li_posdot)),2) as_money = Left(as_money, li_posdot - 1) + Right(String(ld_dec), 3) End If If Len(as_money) > 15 Then MessageBox("Notice", "Money is so large") Return "" End If as_money = Fill(" ", 15 - Len(as_money)) + as_money tenrow = 'Ten Twenty Thirty Forty Fifty Sixty SeventyEighty Ninety ' tenline = ' Eleven Twelve Thirteen Fourteen Fifteen Sixteen SeventeenEighteen Nineteen ' numberchar = 'One Two ThreeFour Five Six SevenEightNine Ten ' denary = Right(as_money, 3) hundreddenary = Right(as_money, 6) For i = 1 To 5 threenumber = Mid(as_money, i*3 - 2, 3) If threenumber <> " " Then Choose Case threenumber Case '000' If i = 4 Then threechar = 'USD' Else threechar = '' End If Case'.00' threechar = '' Case Else threechar = '' If i = 4 And Double(as_money) > Double(hundreddenary) And Double(hundreddenary) <> 0 And Double(denary) = 0 Then threechar = 'and ' End If If i = 4 And Left(hundreddenary,1) = '0' And Double(denary) = 0 Then threechar = 'and ' End If If i = 5 And Double(hundreddenary) >= 1 Then threechar = "and" End If numberone = Left(threenumber, 1) numbertwo = Mid(threenumber, 2, 1) numberthree = Right(threenumber, 1) For j = 1 To 3 translate = '' s = Integer(Mid(threenumber, j, 1)) Choose Case j Case 1 If s > 0 Then translate = Trim(Mid(numberchar, s*5 - 4, 5))+' '+'Hundred ' End If Case 2 e = Integer(numberthree) If s = 1 And numberthree <> '0' Then translate = Trim(Mid(tenline, e*9 - 8, 9))+' ' ElseIf s = 0 And Trim(numberone) <> '' And numberthree <> '0' And i < 5 Then translate = 'and ' ElseIf s > 0 Then translate = Trim(Mid(tenrow, s*7 - 6, 7))+' ' End If Case 3 If s > 0 And numbertwo <> '1' Then If i = 1 Then translate = Trim(Mid(numberchar, s*5 - 4,5))+' '+'Billion ' ElseIf i = 2 Then translate = Trim(Mid(numberchar, s*5 - 4,5))+' '+'Million ' ElseIf i = 3 Then translate = Trim(Mid(numberchar, s*5 - 4,5))+' '+'Thousand ' ElseIf i = 4 And Double(hundreddenary) >= 1 Then translate = Trim(Mid(numberchar, s*5 - 4,5))+' '+'USD' ElseIf i = 5 Then translate = Trim(Mid(numberchar, s*5 - 4,5))+' '+'CENT' End If Else If i = 1 Then translate = ' '+'Billion ' ElseIf i = 2 Then translate = ' '+'Million ' ElseIf i = 3 Then translate = ' '+'Thousand ' ElseIf i = 4 And Double(hundreddenary) >= 1 Then translate = ' ' + 'USD' ElseIf i = 5 Then translate = ' '+'CENT' End If End If End Choose threechar = Trim(threechar)+' '+Trim(translate) Next End Choose result = Trim(result)+' '+threechar End If Next Return result end function |
Find Projects On Github click here
Good Luck!