1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
sys.stdin = io.TextIOWrapper(sys.stdin.buffer,encoding='utf-8') from decimal import Decimal
def cncurrency(value, capital=True, prefix=False, classical=None):
if classical is None: classical = True if capital else False
if prefix is True: prefix = '人民币' else: prefix = ''
if capital: num = ('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖') iunit = [None, '拾', '佰', '仟', '万', '拾', '佰', '仟','亿', '拾', '佰', '仟', '万', '拾', '佰', '仟'] else: num = ('〇', '一', '二', '三', '四', '五', '六', '七', '八', '九') iunit = [None, '十', '百', '千', '万', '十', '百', '千','亿', '十', '百', '千', '万', '十', '百', '千'] if classical: iunit[0] = '元' if classical else '圆'
if not isinstance(value, Decimal): value = Decimal(value).quantize(Decimal('0.01'))
s = str(value) istr, dstr = s.split('.') istr = istr[::-1] so = []
if value == 0: return prefix + num[0] + iunit[0] haszero = False if dstr == '00': haszero = True
for i, n in enumerate(istr): n = int(n) if i % 4 == 0: if i == 8 and so[-1] == iunit[4]: so.pop() so.append(iunit[i]) if n == 0: if not haszero: so.insert(-1, num[0]) haszero = True else: so.append(num[n]) haszero = False else: if n != 0: so.append(iunit[i]) so.append(num[n]) haszero = False else: if not haszero: so.append(num[0]) haszero = True
so.append(prefix) so.reverse() return ''.join(so)
i=input() print (cncurrency(i)+"整")
|