数字转人民币大写

private    string    GetNumToUpper( decimal    Money)
                {
                       
                       
string    NumList   =    "" ;   string    RmbList   =    "" ;
                       
int    NumLen   =    0 ;   int    NumChar   =    0 ;
                       
string    N1   =    "" ,   N2   =    "" ;
                       
decimal    Mnu   =    0 ;
                       
int    I   =    0 ;
                       
string    numStr   =    "" ; string    Change   =    "" ;

                        Mnu  
=    Money;
                       
if    (Money   >    0 )
                        {
                                Money  
=    Convert.ToDecimal(Money.ToString( " #.00 " ));
                        }
                       
else
                        {
                                Money  
=    Convert.ToDecimal(Money.ToString( " #.00 " ))   *    - 1 ;
                        }

                        NumList  
=    " 零壹贰叁肆伍陆柒捌玖 " ;
                        RmbList  
=    " 分角元拾佰仟万拾佰仟亿拾佰仟万 " ;

                       
if    (Money   >    9999999999999.99M )
                        {
                               
return    " ------- " ;     // 超出范围的人民币值,无法显示!;
                        }

                        numStr  
=    Convert.ToString(Convert.ToDecimal(Money   *    100 ).ToString( " # " ));
                        NumLen  
=    numStr.Length;

                        I  
=    0 ;
                       
while    (I   <=    NumLen   - 1 )
                        {
                                NumChar  
=    Convert.ToInt32(numStr.Substring(I,   1 ));
                                N1  
=    NumList.Substring(NumChar,   1 );
                                N2  
=    RmbList.Substring(NumLen   -    I   - 1 ,   1 );
                               
if    (N1   !=    " " )
                                {
                                        Change  
+=    N1   +    N2;
                                }
                               
else
                                {
                                       
if    (N2   ==    " 亿 "    ¦ ¦   N2   ==    " "    ¦ ¦   N2   ==    " "    ¦ ¦   N1   ==    " " )
                                        {
                                               
while    (Change.Substring(Change.Length   -    1 ,   1 )   ==    " " )
                                                {
                                                        Change  
=    Change.Substring( 0 ,   Change.Length   -    1 );
                                                }
                                        }
                                       
if    (N2   ==    " 亿 "    ¦ ¦   (N2   ==    " "    &&    Change.Substring(Change.Length   -    1 ,   1 )   !=    " 亿 " )   ¦ ¦   N2   ==    " " )
                                        {
                                                Change  
+=    N2;
                                        }
                                       
else
                                        {
                                               
if    (Change.Substring(Change.Length   -    2 ,   2 ).Substring( 0 ,   1 )   ==    " "    ¦ ¦   Change.Substring(Change.Length   -    1 ,   1 )   !=    " 亿 " )
                                                {
                                                        Change  
+=    N1;
                                                }
                                        }
                                }
                                I
++ ;
                        }
                       
if    (Change.Length   >    1 )
                        {
                               
while    (Change.Substring(Change.Length   -    1 ,   1 )   ==    " " )
                                {
                                        Change  
=    Change.Substring( 0 ,   Change.Length   -    1 );
                                }
                               
if    (Change.Substring(Change.Length   -    1 ,   1 )   ==    " "    ¦ ¦   Change.Substring(Change.Length   -    1 ,   1 )   ==    " " )
                                {
                                        Change  
+=    " " ;
                                }
                        }
                       
                                             
                       
if    (Mnu   >    0 )
                        {
                               
return    Change;
                        }
                       
else    if    (Mnu   <    0 )
                        {
                               
return    " "    +    Change;
                        }
                       
else
                        {
                               
return    " 零元整 " ;
                        }  
                }
好的,我可以为您解答这个问题。 Oracle中可以使用PL/SQL代码将数字换为人民币大写。以下是一个示例代码: ``` CREATE OR REPLACE FUNCTION f_num2rmb(p_num IN NUMBER) RETURN VARCHAR2 IS l_num NUMBER := TRUNC(p_num); l_dec NUMBER(2,0) := TRUNC(MOD(p_num, 1) * 100); l_rmb VARCHAR2(200); l_unit CONSTANT VARCHAR2(10) := '元'; l_decimal CONSTANT VARCHAR2(10) := '角分'; l_numstr CONSTANT VARCHAR2(50) := '零壹贰叁肆伍陆柒捌玖'; l_unitstr CONSTANT VARCHAR2(50) := '仟佰拾'; l_decimalstr CONSTANT VARCHAR2(50) := '分角'; BEGIN IF l_num = 0 AND l_dec = 0 THEN RETURN '零元整'; END IF; l_rmb := TO_CHAR(l_dec, 'FM00') || l_decimal; FOR i IN 1..4 LOOP l_unitstr := SUBSTR(l_unitstr, 2); IF l_num = 0 THEN EXIT; END IF; l_rmb := SUBSTR(l_numstr, MOD(TRUNC(l_num / POWER(10, (4 - i) * 4)), 10) + 1, 1) || l_unitstr || l_rmb; l_num := TRUNC(l_num / 10); END LOOP; l_rmb := REPLACE(l_rmb, '零仟', '零'); l_rmb := REPLACE(l_rmb, '零佰', '零'); l_rmb := REPLACE(l_rmb, '零拾', '零'); l_rmb := REPLACE(l_rmb, '零零零', '零'); l_rmb := REPLACE(l_rmb, '零零', '零'); l_rmb := REPLACE(l_rmb, '零角零分', '整'); IF SUBSTR(l_rmb, 1, 1) = '零' THEN l_rmb := SUBSTR(l_rmb, 2); END IF; RETURN l_rmb || l_unit || '整'; END; / ``` 使用该函数,可以将数字换为人民币大写。例如: ``` SELECT f_num2rmb(12345.67) FROM DUAL; ``` 输出结果为: ``` 壹万贰仟叁佰肆拾伍元陆角柒分整 ``` 这个函数的代码实现比较复杂,但是可以通过调用该函数来轻松地将数字换为人民币大写
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值