def number_as_currency_text(value, case = "im"): from common_utils import word_from_num, num_word, chunks if isinstance(value, dict): decival = Decimal(value['value']) elif isinstance(value, DocField): decival = value.db_value() else: decival = Decimal(value) is_minus = decival < 0 if is_minus: decival = -decival decival_str = str(decival) rubles = int(decival_str.split('.')[0] if '.' in decival_str else decival_str) rubles_splited = u' '.join([_ for _ in chunks(unicode(rubles)[::-1], 3)])[::-1] rubles_text = num_word(rubles, padezh=case) cur_word_maj = u"рубль" cur_word_min = u"копейка" min_str = decival_str.split('.')[1] if '.' in decival_str else '0' if len(min_str) < 2: min_str += u"0" currency_minor = int(min_str) rubles_word = word_from_num(cur_word_maj, rubles, padezh=case) copeek_word = word_from_num(cur_word_min, currency_minor, padezh=case) copeek_num = unicode(currency_minor) if len(copeek_num) < 2: copeek_num = u"0" + copeek_num if is_minus: return u"минус %s (%s) %s %s %s" % (rubles_splited, rubles_text, rubles_word, copeek_num, copeek_word) return u"%s (%s) %s %s %s" % (rubles_splited, rubles_text, rubles_word, copeek_num, copeek_word)
def adapt(value): if not isinstance(value, int): return return num_word(value)
def num_to_text(value, gender='m', padezh='im'): return num_word(value, gender, padezh)
from common_utils import word_from_num, num_word, chunks if isinstance(value, dict): decival = Decimal(value['value']) elif isinstance(value, DocField): decival = value.db_value() else: decival = Decimal(value) is_minus = decival < 0 if is_minus: decival = -decival decival_str = str(decival) rubles = int( decival_str.split('.')[0] if '.' in decival_str else decival_str) rubles_splited = u' '.join([_ for _ in chunks(unicode(rubles)[::-1], 3) ])[::-1] rubles_text = num_word(rubles, padezh=case) cur_word_maj = u"рубль" cur_word_min = u"копейка" min_str = decival_str.split('.')[1] if '.' in decival_str else '0' if len(min_str) < 2: min_str += u"0" currency_minor = int(min_str) rubles_word = word_from_num(cur_word_maj, rubles, padezh=case) copeek_word = word_from_num(cur_word_min, currency_minor, padezh=case) copeek_num = unicode(currency_minor) if len(copeek_num) < 2: copeek_num = u"0" + copeek_num if is_minus: return u"минус %s (%s) %s %s %s" % (
def num_to_text(value): if not isinstance(value, int): return return num_word(value)