mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
* add Thai * change splitby3 to splitbyx * change lang_th to use function from currency * make Num2Word_TH inherit from Num2Word_Base * comment out test failed in 2.7 env * fix python2.7 error * add USD EUR for Thai * pep8 fix * added Thai
34 lines
888 B
Python
34 lines
888 B
Python
from __future__ import division
|
|
|
|
from decimal import ROUND_HALF_UP, Decimal
|
|
|
|
|
|
def parse_currency_parts(value, is_int_with_cents=True):
|
|
if isinstance(value, int):
|
|
if is_int_with_cents:
|
|
# assume cents if value is integer
|
|
negative = value < 0
|
|
value = abs(value)
|
|
integer, cents = divmod(value, 100)
|
|
else:
|
|
negative = value < 0
|
|
integer, cents = abs(value), 0
|
|
|
|
else:
|
|
value = Decimal(value)
|
|
value = value.quantize(
|
|
Decimal('.01'),
|
|
rounding=ROUND_HALF_UP
|
|
)
|
|
negative = value < 0
|
|
value = abs(value)
|
|
integer, fraction = divmod(value, 1)
|
|
integer = int(integer)
|
|
cents = int(fraction * 100)
|
|
|
|
return integer, cents, negative
|
|
|
|
|
|
def prefix_currency(prefix, base):
|
|
return tuple("%s %s" % (prefix, i) for i in base)
|