mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Added ability to display cents as numbers
This commit is contained in:
@@ -110,7 +110,7 @@ class Num2Word_EN(num2word_EU.Num2Word_EU):
|
||||
|
||||
def to_currency(self, val, longval=True):
|
||||
return self.to_splitnum(val, hightxt="dollar/s", lowtxt="cent/s",
|
||||
jointxt="and", longval=longval)
|
||||
jointxt="and", longval=longval, cents = True)
|
||||
|
||||
|
||||
n2w = Num2Word_EN()
|
||||
|
||||
@@ -34,9 +34,9 @@ from num2word_EN import Num2Word_EN
|
||||
|
||||
|
||||
class Num2Word_EN_EUR(Num2Word_EN):
|
||||
def to_currency(self, val, longval=True):
|
||||
def to_currency(self, val, longval=True, cents=True, jointxt="and"):
|
||||
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cents",
|
||||
jointxt="and", longval=longval)
|
||||
jointxt=jointxt, longval=longval, cents = cents)
|
||||
|
||||
|
||||
n2w = Num2Word_EN_EUR()
|
||||
|
||||
@@ -191,7 +191,7 @@ def n2w(n):
|
||||
else:
|
||||
return int2word(int(n))
|
||||
|
||||
def to_currency(n, currency='LTL'):
|
||||
def to_currency(n, currency='LTL', cents = True):
|
||||
if type(n) == int:
|
||||
left = abs(n / 100)
|
||||
right = abs(n % 100)
|
||||
@@ -214,8 +214,13 @@ def to_currency(n, currency='LTL'):
|
||||
else:
|
||||
minus_str = ""
|
||||
|
||||
if cents:
|
||||
cents_str = int2word(right)
|
||||
else:
|
||||
cents_str = "%02d" % right
|
||||
|
||||
return u'%s%s %s, %s %s' % (minus_str, int2word(left), pluralize(left, cr1),
|
||||
int2word(right), pluralize(right, cr2))
|
||||
cents_str, pluralize(right, cr2))
|
||||
|
||||
to_card = n2w
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ class Num2Word_Base(object):
|
||||
|
||||
#//CHECK: generalise? Any others like pounds/shillings/pence?
|
||||
def to_splitnum(self, val, hightxt="", lowtxt="", jointxt="",
|
||||
divisor=100, longval=True):
|
||||
divisor=100, longval=True, cents = True):
|
||||
out = []
|
||||
try:
|
||||
high, low = val
|
||||
@@ -224,7 +224,10 @@ class Num2Word_Base(object):
|
||||
elif hightxt:
|
||||
out.append(hightxt)
|
||||
if low:
|
||||
if cents:
|
||||
out.append(self.to_cardinal(low))
|
||||
else:
|
||||
out.append("%02d" % low)
|
||||
if lowtxt and longval:
|
||||
out.append(self.title(self.inflect(low, lowtxt)))
|
||||
return " ".join(out)
|
||||
|
||||
Reference in New Issue
Block a user