unit money; { Michael Gibbs } { This unit provides a routine for converting a string of digits } { into check format, i.e., written out as dollars and cents using } { words. For example, the string '127.45' is converted to } { 'One Hundred Twenty Seven and 45/100'. } { NOTE: the input number is a string. } interface procedure dollars2Text (amount: str255; var textAmount: str255); implementation procedure dollars2Text (amount: str255; var textAmount: str255); var temp, num: str255; hundreds: boolean; x: integer; procedure part1; begin case num[length(num)] of '0': textAmount := concat(' Ten', textAmount); '1': textAmount := concat(' Eleven', textAmount); '2': textAmount := concat(' Twelve', textAmount); '3': textAmount := concat(' Thirteen', textAmount); '4': textAmount := concat(' Fourteen', textAmount); '5': textAmount := concat(' Fifteen', textAmount); '6': textAmount := concat(' Sixteen', textAmount); '7': textAmount := concat(' Seventeen', textAmount); '8': textAmount := concat(' Eighteen', textAmount); '9': textAmount := concat(' Nineteen', textAmount); end; end; procedure part2; begin case num[length(num)] of '0': ; '1': textAmount := concat(' One', textAmount); '2': textAmount := concat(' Two', textAmount); '3': textAmount := concat(' Three', textAmount); '4': textAmount := concat(' Four', textAmount); '5': textAmount := concat(' Five', textAmount); '6': textAmount := concat(' Six', textAmount); '7': textAmount := concat(' Seven', textAmount); '8': textAmount := concat(' Eight', textAmount); '9': textAmount := concat(' Nine', textAmount); end; if not hundreds then case num[length(num) - 1] of '0': ; '1': ; '2': textAmount := concat(' Twenty', textAmount); '3': textAmount := concat(' Thirty', textAmount); '4': textAmount := concat(' Forty', textAmount); '5': textAmount := concat(' Fifty', textAmount); '6': textAmount := concat(' Sixty', textAmount); '7': textAmount := concat(' Seventy', textAmount); '8': textAmount := concat(' Eighty', textAmount); '9': textAmount := concat(' Ninety', textAmount); end; end; begin if (length(amount) <= 8) & (pos('.', amount) <= 6) then begin hundreds := false; num := amount; x := pos('.', num); if x < 3 then begin num := concat('00', num); x := pos('.', num); end; textAmount := ' Dollars'; temp := copy(num, x + 1, 2); textAmount := concat(' and ', temp, '/100', textAmount); delete(num, x, 3); if num[length(num) - 1] = '1' then part1 else part2; delete(num, length(num) - 1, 2); if length(num) <> 0 then begin if num[length(num)] <> '0' then textAmount := concat(' Hundred', textAmount); hundreds := true; part2; hundreds := false; delete(num, length(num), 1); if length(num) <> 0 then begin textAmount := concat(' Thousand', textAmount); if num[length(num) - 1] = '1' then part1 else part2; end; end; end else textAmount := ''; end; end.