/[gnue]/gnue-common/src/utils/TextUtils.py
ViewVC logotype

Diff of /gnue-common/src/utils/TextUtils.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by jcater, Sat Jun 7 07:22:56 2003 UTC revision 1.8 by jcater, Sun Jul 27 23:55:23 2003 UTC
# Line 126  _tenDollarMap = ('', '', 'Twenty ', 'Thi Line 126  _tenDollarMap = ('', '', 'Twenty ', 'Thi
126  _thirdDollarMap = ('', 'Thousand ', 'Million ', 'Billion ', 'Trillion ')  _thirdDollarMap = ('', 'Thousand ', 'Million ', 'Billion ', 'Trillion ')
127    
128    
129    
130    # Comify a number
131    # (e.g., print -9900 as -9,900.00)
132    def comify(num, decimals=2, parenthesis=0):
133      whole, dec = (string.split(string.strip(("%%12.%sf" % decimals) % abs(num)),'.') + [""])[:2]
134      if len(dec):
135        dec = "." + dec
136    
137      s = ""
138    
139      for i in range(divmod(len(whole),3)[0]+1):
140        j = len(whole) - i*3
141        s = "," + whole[j > 3 and j-3 or 0:j] + s
142    
143      s += dec
144    
145      while s[:1] == ',':
146        s = s[1:]
147    
148      if num < 0:
149        if parenthesis:
150          s = "(%s)" % s
151        else:
152          s = "-" + s
153      elif parenthesis:
154        s += " "
155    
156      return s

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26