1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>
21
##############################################################################
23
# can be used for numbers as large as 999 vigintillion
24
# (vigintillion --> 10 to the power 60)
25
# tested with Python24 vegaseat 07dec2006
29
convert an integer number n into a string of English words
31
# break the number into groups of 3 digits using slicing
32
# each group representing hundred, thousand, million, billion, ...
37
# create numeric string
39
for k in range(3, 33, 3):
42
# break if end of ns has been reached
54
for i, x in enumerate(n3):
57
b3 = (x % 1000) // 100
63
nw = ones[b1] + t + nw
65
nw = tens[b1] + t + nw
67
nw = twenties[b2] + ones[b1] + t + nw
69
nw = ones[b3] + "hundred " + nw
72
############# globals ################
74
ones = ["", "One ", "Two ", "Three ", "Four ", "Five ",
75
"Six ", "Seven ", "Eight ", "Nine "]
77
tens = ["Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
78
"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "]
80
twenties = ["", "", "Twenty ", "Thirty ", "Forty ",
81
"Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "]
83
thousands = ["", "Thousand ", "Million ", "Billion ", "Trillion ",
84
"Quadrillion ", "Quintillion ", "Sextillion ", "Septillion ","Octillion ",
85
"Nonillion ", "Decillion ", "Undecillion ", "Duodecillion ", "Tredecillion ",
86
"Quattuordecillion ", "Sexdecillion ", "Septendecillion ", "Octodecillion ",
87
"Novemdecillion ", "Vigintillion "]
89
def amount_to_words(num):
90
# select an integer number n for testing or get it from user input
94
num = float(str(num)[1:])
95
if num == 0: return 'Zero'
97
n = str(num).split('.')
98
return res + int2word(int(n[0])) + 'and ' + (len(n) > 1 and int(n[1]) and str((num - int(num)) * 100).split('.')[0] or 'no') + '/100s'
100
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'