The following article mainly introduces an example of the actual application code in Python code that converts the amount to lowercase to uppercase, if you use Python code to convert the amount to uppercase in lower case, the actual operations are confusing. You can click the following article to learn about it.
Keywords: Decorator connecting to Oracle Database SQLObject design mode TurboGears test framework
This article describes how to convert a lower-case amount to a larger-case Python code function to convert a lower-case amount less than 100,000 million yuan to an upper-case value.
Code
- CODE:
- Def IIf (B, s1, s2 ):
- If B:
- Return s1
- Else:
- Return s2
- Def num2chn (nin = None ):
- Cs =
- ('0', 'yi', 'er', 'san', 'siz', 'wu', 'lu', 'taobao', 'taobao ', 'taobao', '◇ ', 'quantity', 'angular', 'circle ', 'scuse', 'taobao', 'taobao ',
- 'Wan', 'pick', 'taobao', 'taobao', 'yiyi', 'pick', 'taobao', 'wan ')
- St = ''; st1 =''
- S = '% 0.2f' % (nin)
- Sln = len (s)
- If sln>; 15: return None
- Fg = (nin <1)
- For I in range (0, sln-3 ):
- Ns = ord (s [sln-i-4])-ord ('0 ')
- St = IIf (ns = 0) and (fg or (I = 8) or (I = 4) or (I = 0 )),'', cs [ns])
- + IIf (ns = 0) and (I <>; 8) and (I <>; 4) and (I <>; 0) or fg
- And (I = 0), '', cs [I + 13])
- + St
- Fg = (ns = 0)
- Fg = False
- For I in [1, 2]:
- Ns = ord (s [sln-I])-ord ('0 ')
- St1 = IIf (ns = 0) and (I = 1) or (I = 2) and (fg or (nin <1 ))),'', cs [ns])
- + IIf (ns>; 0), cs [I + 10], IIf (I = 2) or fg, '', 'rounded '))
- + St1
- Fg = (ns = 0)
- St. replace ('billions ', 'wan ')
- Return IIf (nin = 0, '0', st + st1)
- If _ name _ = '_ main __':
- Num = 12340.1
- Print num
- Print num2chn (num)
Detailed explanation of converting the amount to uppercase in Python code in lower case