def cn_digit(s): if isinstance(s, (int, float)): s = str(s) elif not isinstance(s, str): return s s = s.replace(',', '') m = re.match(r'(-?)(\d+)((?:\.\d+)?)', s, re.A) if not m: return s intpart = m.group(2) dem = "万亿兆京垓秭穰沟涧正载极" result = intpart[-4:] for i in range(-4,-len(intpart),-4): result = intpart[i-4:i] + dem[-i//4-1] + result return m.group(1) + result + m.group(3)
def cn_digit(s): if isinstance(s, (int, float)): s = str(s) elif not isinstance(s, str): return s s = s.replace(',', '') m = re.match(r'(-?)(\d+)((?:\.\d+)?)', s, re.A) if not m: return s intpart = m.group(2) dem = "万亿兆京垓秭穰沟涧正载极" result = intpart[-4:] for i in range(-4,-min(len(intpart), 4*(len(dem)+1)),-4): result = intpart[i-4:i] + dem[-i//4-1] + result return m.group(1) + intpart[0:-4*(len(dem)+1)] + result + m.group(3)
def cn_digit(s): if isinstance(s, (int, float)): s = str(s) elif not isinstance(s, str): return s s = s.replace(',', '') m = re.match(r'(-?)(\d+)((?:\.\d+)?)', s, re.A) if not m: return s intpart = m.group(2) dem = "万亿兆京垓秭穰沟涧正载极" thousands = intpart[-4:] cn_dig = [intpart[i-4:i] + dem[-i//4-1] for i in range(-4,-min(len(intpart), 4*(len(dem)+1)),-4)] return m.group(1) + intpart[0:-4*(len(dem)+1)] + ''.join(reversed(cn_dig)) + thousands + m.group(3)
def cn_digit(s): if isinstance(s, (int, float)): s = str(s) elif not isinstance(s, str): return s s = s.replace(',', '') m = re.match(r'(-?)(\d+)((?:\.\d+)?)', s, re.A) if not m: return s dem = "万亿兆京垓秭穰沟涧正载极" cn_dig = [v + dem[i//4-1] if i > 1 and i % 4 == 0 and i // 4 <= len(dem) else v for i,v in enumerate(m.group(2)[::-1])] return m.group(1) + ''.join(reversed(cn_dig)) + m.group(3)