人民币大写金额转换

#include<iostream>
using namespace std;
char exchange(int a);
int search1(int a)
{
    ///
    int yi,qw,bw,sw,w,k=0,b=0,shi=0,ge=0;
    int &s=shi;
    char store[9];
     ge=a%10;//个位
    shi=(a%100-ge)/10;//十位
      b=(a%1000-shi*10-ge)/100;//百位
      k=(a%10000-b*100-shi*10-ge)/1000;//千位
      w=(a%100000-k*1000-b*100-shi*10-ge)/10000;
     sw=(a%1000000-w*10000-k*1000-b*100-shi*10-ge)/100000;//十万
     bw=(a%10000000-sw*100000-w*10000-k*1000-b*100-shi*10-ge)/1000000;//百万
     qw=(a%100000000-bw*1000000-sw*100000-w*10000-k*1000-b*100-shi*10-ge)/10000000;//千万
     yi=(a-a%10000000)/100000000;//亿
    
     
    if(yi!=0)
     {
         
         cout<<exchange(yi)<<"亿";}

         if(qw==0)
         {
             if(bw==0)
             {
                 if(sw==0)
                 {
                     if(w==0)
                     {}
                    else
                    {
                        cout<<exchange(w)<<"万";
                     } 
                 }
                else if(sw!=0)
                {
                    if(w==0)
                     {
                     cout<<exchange(sw)<<"十万零";
                     }
                    else
                    {
                    
                        cout<<exchange(sw)<<"拾";
                        cout<<exchange(w)<<"万";
                     } 
                 }
                }
            else if(bw!=0)
            {
                if(sw==0)
                 {
                     if(w==0)
                     {cout<<exchange(bw)<<"百万零";}
                    else
                    {
                        cout<<exchange(bw)<<"百零";
                        cout<<exchange(w)<<"万";
                     } 
                 }
                else if(sw!=0)
                {
                    if(w==0)
                     {
                         cout<<exchange(bw)<<"百";
                         cout<<exchange(sw)<<"十";
                        cout<<exchange(w)<<"万零";
                     }
                    else
                    {
                        cout<<exchange(bw)<<"百";
                        cout<<exchange(sw)<<"拾"; 
                        cout<<exchange(w)<<"万";
                     } 
                 }
            }    
         }
         else if(qw!=0)
         {
             if(bw==0)
             {
                 if(sw==0)
                 {
                     if(w==0)
                     {cout<<exchange(qw)<<"千万零";}
                    else
                    {
                        cout<<exchange(qw)<<"千零";
                        cout<<exchange(w)<<"万";
                     } 
                 }
                else if(sw!=0)
                {
                    if(w==0)
                     {
                      cout<<exchange(qw)<<"千零";
                     cout<<exchange(sw)<<"十万零";
                     }
                    else
                    {
                        cout<<exchange(qw)<<"千零";
                        cout<<exchange(sw)<<"拾";
                        cout<<exchange(w)<<"万";
                     } 
                 }
                }
            else if(bw!=0)
            {
                if(sw==0)
                 {
                     if(w==0)
                     {
                      cout<<exchange(qw)<<"千";
                     cout<<exchange(bw)<<"百万零";
                     }
                    else
                    {
                        cout<<exchange(qw)<<"千";
                        cout<<exchange(bw)<<"百零";
                        cout<<exchange(w)<<"万";
                     } 
                 }
                else if(sw!=0)
                {
                    if(w==0)
                     {
                        cout<<exchange(qw)<<"千";
                        cout<<exchange(bw)<<"百";
                        cout<<exchange(sw)<<"十万零";
                     }
                    else
                    {
                        cout<<exchange(qw)<<"千";
                        cout<<exchange(bw)<<"百";
                        cout<<exchange(sw)<<"十";
                        cout<<exchange(w)<<"万";
                     } 
                 }
            }
             
         }
         if(w!=0 && k==0)
         {
             cout<<"零"; 
         }
         if(k==0)
         {
             if(b==0)
             {
                 if(s==0)
                 {
                     if(ge==0)
                     {}
                    else
                    {
                        cout<<exchange(ge);
                     } 
                 }
                else if(s!=0)
                {
                    if(ge==0)
                     {
                     cout<<exchange(s)<<"十零";
                     }
                    else
                    {
                    
                        cout<<exchange(s)<<"拾";
                        cout<<exchange(ge);
                     } 
                 }
                }
            else if(b!=0)
            {
                if(s==0)
                 {
                     if(ge==0)
                     {cout<<exchange(b)<<"百零";}
                    else
                    {
                        cout<<exchange(b)<<"百零";
                        cout<<exchange(ge);
                     } 
                 }
                else if(s!=0)
                {
                    if(ge==0)
                     {
                         cout<<exchange(b)<<"百";
                         cout<<exchange(s)<<"十";
                        cout<<exchange(ge);
                     }
                    else
                    {
                        cout<<exchange(b)<<"百";
                        cout<<exchange(s)<<"拾"; 
                        cout<<exchange(ge);
                     } 
                 }
            }    
         }
         else if(k!=0)
         {
             if(b==0)
             {
                 if(s==0)
                 {
                     if(ge==0)
                     {cout<<exchange(k)<<"千零";}
                    else
                    {
                        cout<<exchange(k)<<"千零";
                        cout<<exchange(ge);
                     } 
                 }
                else if(s!=0)
                {
                    if(ge==0)
                     {
                      cout<<exchange(k)<<"千零";
                     cout<<exchange(s)<<"十万零";
                     }
                    else
                    {
                        cout<<exchange(k)<<"千零";
                        cout<<exchange(s)<<"十";
                        cout<<exchange(ge);
                     } 
                 }
                }
            else if(b!=0)
            {
                if(s==0)
                 {
                     if(ge==0)
                     {
                      cout<<exchange(k)<<"千";
                     cout<<exchange(b)<<"百零";
                     }
                    else
                    {
                        cout<<exchange(k)<<"千";
                        cout<<exchange(b)<<"百零";
                        cout<<exchange(ge);
                     } 
                 }
                else if(s!=0)
                {
                    if(ge==0)
                     {
                        cout<<exchange(k)<<"千";
                        cout<<exchange(b)<<"百";
                        cout<<exchange(s)<<"十零";
                     }
                    else
                    {
                        cout<<exchange(k)<<"千";
                        cout<<exchange(b)<<"百";
                        cout<<exchange(s)<<"十";
                        cout<<exchange(ge);
                     } 
                 }
            }
             
         }
}
char exchange(int a)
{
    if(a==1)
        cout<<" 壹";
    else if(a==2)
        cout<<" 贰";
    else if(a==3)
        cout<<" 叁";
    else if(a==4)
        cout<<" 肆";
    else if(a==5)
        cout<<" 伍";
    else if(a==6)
        cout<<" 陆";
    else if(a==7)
        cout<<" 柒";
    else if(a==8)
        cout<<" 八";
    else if(a==9)
        cout<<" 玖";
    return ' ';
}; 
int main()
{
    int a;
    cout<<"请输入金额"<<endl;
    cin>>a;
    if(a>999999999)
    cout<<"数据溢出,请输入十亿以内的数字"<<endl;
    else if(a<999999999&&a>0)
    {
       cout<<"转换大写后的金额为"<<endl;    
       search1(a);
    }
    else if(a==0)
    cout<<"零";
    return 0;
}

数字转成人民币大写代码 Public Function GetChinaNum(otherNum As Double, Optional isRMB As Boolean, Optional numOption As Boolean, Optional dotNum As Integer) As String On Error Resume Next num = Trim(Str(Int(otherNum))) If isRMB Then numwei = "拾佰仟万拾佰仟亿拾佰仟" numshu = "零壹贰叁肆伍陆柒捌玖拾" Else numwei = "十百千万十百千亿十百千" numshu = "零一二三四五六七八九十" End If If otherNum < 20 And otherNum >= 10 Then num = Right(num, 1) GetChinaNum = Left(numwei, 1) End If For i = 1 To Len(num) bstr = Mid(num, i, 1) If numOption Then GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) Else GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) If bstr = "0" Then If Mid(numwei, Len(num) - i, 1) = "万" Or Mid(numwei, Len(num) - i, 1) = "亿" Then Do While Right(GetChinaNum, 1) = "零" GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1) Loop GetChinaNum = GetChinaNum + Mid(numwei, Len(num) - i, 1) End If Else GetChinaNum = GetChinaNum + Mid(numwei, Len(num) - i, 1) End If GetChinaNum = Replace(GetChinaNum, "零零", "零") End If Next i If numOption = False Then Do While Right(GetChinaNum, 1) = "零" GetChinaNum = Left(GetChinaNum, Len(GetChinaNum) - 1) Loop End If If isRMB Then numrmb = "元角分" GetChinaNum = GetChinaNum + Mid(numrmb, 1, 1) If Val(num) <> otherNum Then num = Trim(Str(Round(otherNum - Val(num), 2))) For i = 2 To Len(num) bstr = Mid(num, i, 1) GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) + Mid(numrmb, i, 1) Next i Else GetChinaNum = GetChinaNum + "整" End If Else If Val(num) <> otherNum Then If dotNum = 0 Then dotNum = 4 num = Trim(CStr(Round(otherNum - Val(num), dotNum))) If GetChinaNum = "" Then GetChinaNum = "零" GetChinaNum = GetChinaNum + "点" For i = 2 To Len(num) bstr = Mid(num, i, 1) GetChinaNum = GetChinaNum + Mid(numshu, Val(bstr) + 1, 1) Next i End If End If End Function
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值