Arabic numerals to uppercase Chinese-commonly used Finance

Source: Internet
Author: User

Requirement: enter an Arabic number, give the corresponding Chinese Characters in uppercase, and write it as a stored procedure or function.

For example, enter 12345, and the program will show you:
For example, enter 10023040, and the program will provide the following information:

One solution (tested in sqlserver2000 ):
Create Function fun_cgnum
(@ Num INT)
Returns varchar (100)
As
Begin
Declare @ temp int, @ Res Int, @ I tinyint
Declare @ STR varchar (100), @ No varchar (20), @ unit varchar (16)
Select @ STR = '', @ No = 'another employee, Wu Luhan, Wu luyun, @ unit = 'yaohan wanzhibaibaibaibaibaiyi'
Set @ temp = @ num
Select @ I = 0, @ res = @ TEMP % 10, @ temp = @ temp/10
While @ temp> 0
Begin
If @ I = 0
Set @ STR = substring (@ No, @ res + 1, 1)
Else
Set @ STR = substring (@ No, @ res + 1,1) + substring (@ unit, @ I, 1) + @ Str
Select @ res = @ TEMP % 10, @ temp = @ temp/10
Set @ I = @ I + 1
End
Set @ STR = substring (@ No, @ res + 1,1) + substring (@ unit, @ I, 1) + @ Str
Set @ STR = Replace (@ STR, 'taobao', 'taobao ')
Set @ STR = Replace (@ STR, 'taobao', 'taobao ')
Set @ STR = Replace (@ STR, 'taobao', 'taobao ')
Set @ STR = Replace (@ STR, 'taobao', 'taobao ')
Set @ STR = Replace (@ STR, 'wan Wan ', 'wan ')
While @ I> 0
Begin
Set @ STR = Replace (@ STR, 'others', 'others ')
Set @ I = charindex ('others', @ Str)
End
Set @ STR = Replace (@ STR, 'wan Wan ', 'wan ')
Set @ STR = Replace (@ STR, 'billionaire, '')
If right (@ STR, 1) = 'others'
Set @ STR = left (@ STR, Len (@ Str)-1)
Return @ Str
End
Go

-- Test: zero or zero
Select DBO. fun_cgnum (900000000), DBO. fun_cgnum (903002051), DBO. fun_cgnum (903002050)

PS: If you are interested, you can continue to consider the number of decimal points and the unit of adding (Yuan/angle/points ).

 

Related Article

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.