Convert the case-sensitive amount in Python code

Source: Internet
Author: User

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

 
 
  1. CODE:
  2. Def IIf (B, s1, s2 ):
  3. If B:
  4. Return s1
  5. Else:
  6. Return s2
  7. Def num2chn (nin = None ):
  8. Cs =
  9. ('0', 'yi', 'er', 'san', 'siz', 'wu', 'lu', 'taobao', 'taobao ', 'taobao', '◇ ', 'quantity', 'angular', 'circle ', 'scuse', 'taobao', 'taobao ',
  10. 'Wan', 'pick', 'taobao', 'taobao', 'yiyi', 'pick', 'taobao', 'wan ')
  11. St = ''; st1 =''
  12. S = '% 0.2f' % (nin)
  13. Sln = len (s)
  14. If sln>; 15: return None
  15. Fg = (nin <1)
  16. For I in range (0, sln-3 ):
  17. Ns = ord (s [sln-i-4])-ord ('0 ')
  18. St = IIf (ns = 0) and (fg or (I = 8) or (I = 4) or (I = 0 )),'', cs [ns])
  19. + IIf (ns = 0) and (I <>; 8) and (I <>; 4) and (I <>; 0) or fg
  20. And (I = 0), '', cs [I + 13])
  21. + St
  22. Fg = (ns = 0)
  23. Fg = False
  24. For I in [1, 2]:
  25. Ns = ord (s [sln-I])-ord ('0 ')
  26. St1 = IIf (ns = 0) and (I = 1) or (I = 2) and (fg or (nin <1 ))),'', cs [ns])
  27. + IIf (ns>; 0), cs [I + 10], IIf (I = 2) or fg, '', 'rounded '))
  28. + St1
  29. Fg = (ns = 0)
  30. St. replace ('billions ', 'wan ')
  31. Return IIf (nin = 0, '0', st + st1)
  32. If _ name _ = '_ main __':
  33. Num = 12340.1
  34. Print num
  35. Print num2chn (num)

Detailed explanation of converting the amount to uppercase in Python code in lower case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.