[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src/utils TextUtils.py
From: |
Jason Cater |
Subject: |
gnue/common/src/utils TextUtils.py |
Date: |
Sat, 07 Jun 2003 03:22:56 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Branch:
Changes by: Jason Cater <address@hidden> 03/06/07 03:22:56
Modified files:
common/src/utils: TextUtils.py
Log message:
added a convenience routine to convert 123.22 to 'One Hundred Twenty
Three and 22/100' (needed for some check printing stuff)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/utils/TextUtils.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gnue/common/src/utils/TextUtils.py
diff -c gnue/common/src/utils/TextUtils.py:1.6
gnue/common/src/utils/TextUtils.py:1.7
*** gnue/common/src/utils/TextUtils.py:1.6 Wed Apr 30 16:38:28 2003
--- gnue/common/src/utils/TextUtils.py Sat Jun 7 03:22:56 2003
***************
*** 88,90 ****
--- 88,128 ----
rv += rom;
return rv
+
+ #
+ # Convert a number to "dollar" notation (suitable for use on checks)
+ # e.g., 123.24 --> "One Hundred Twenty Three and 24/100"
+ #
+ def dollarToText(num):
+ whole = int(num)
+ cents = round((num-whole)*100)
+ rv = 'and %02d/100' % cents
+ if whole:
+ thirdRange = 0
+ while whole:
+ whole, segment = divmod(whole, 1000)
+ hundreds, tens = divmod(segment, 100)
+ try:
+ rv = _smallDollarMap[tens] + _thirdDollarMap[thirdRange] + rv
+ except IndexError:
+ ten, ones = divmod(tens,10)
+ rv = _tenDollarMap[ten] + _smallDollarMap[ones] +
_thirdDollarMap[thirdRange] + rv
+ if hundreds:
+ rv = _smallDollarMap[hundreds] + 'Hundred ' + rv
+ thirdRange += 1
+ else:
+ rv = 'Zero ' + rv
+
+ return rv
+
+
+ _smallDollarMap = ('', 'One ', 'Two ', 'Three ', 'Four ', 'Five ',
+ 'Six ', 'Seven ', 'Eight ', 'Nine ', 'Ten ',
+ 'Eleven ', 'Twelve ', 'Thirteen ', 'Fourteen ',
+ 'Fifteen ', 'Sixteen ', 'Seventeen ', 'Eighteen ',
+ 'Nineteen ' )
+ _tenDollarMap = ('', '', 'Twenty ', 'Thirty ', 'Forty ', 'Fifty ',
+ 'Sixty ', 'Seventy ', 'Eighty ', 'Ninety ')
+ _thirdDollarMap = ('', 'Thousand ', 'Million ', 'Billion ', 'Trillion ')
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/common/src/utils TextUtils.py,
Jason Cater <=