Added ability to display cents as numbers

This commit is contained in:
Marius Grigaitis
2011-07-07 17:42:29 +03:00
parent dee0d135ac
commit bbc175b3bc
5 changed files with 16 additions and 8 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -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)

View File

@@ -1,7 +1,7 @@
from setuptools import setup
setup(name='pynum2word',
version=0.41,
version=0.42,
description='Modules to convert numbers to words. Easily extensible.',
author='Taro Ogawa <tso at users sourceforge net>',
author_email='tos@users.sourceforge.net',