怎样转换金额从数字到大写?谢谢!

解决方案 »

  1.   

    void CTest2Dlg::OnOK() 
    {
    // TODO: Add extra validation here
    float f  = 12345.25;
    CString num[] =  {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
    CString bit[] = {"","拾","佰","仟","万","亿"};
    CString x,s,t;
    int n;
    s.Format ("%f",f);
    int i = s.Find (".");
    if ( i > 12 ) return;
    i--;
    for (int  j=0;j <= i;j++)
    {
    n = char(s.GetAt (i-j)) -48 ;
    if ( j == 8) x = bit[5];
    else x = bit[j%5];
    t = num[n] + x + t;
    }
    t += "圆";
    i = i+2;
    n = char(s.GetAt (i)) -48 ;
    t += num[n] + "角";
    i++;
    n = char(s.GetAt (i)) -48 ;
    t += num[n] + "分";
    m_strUp = t ;//m_strUP 是edit的string变量
    UpdateData(FALSE);
    }
      

  2.   

    #include <stdio.h>
    #include <string.h>
    const char* RMB(double rmb)
    {
        if(rmb<0) return NULL;
    static char *CCC[10]={ //Capital form of Chinese character
         "零","壹","贰","叁","肆","伍","陆","柒","捌","玖"
        };
        static char *QQQ[19]={"分","角",".","圆","拾","佰","仟","万","拾","佰","仟","亿",
         "拾","佰","仟","万","拾","佰","仟"
        };
        static char result[256],tmp[256];
        sprintf(tmp,"%.2lf",rmb);
        if(strlen(tmp)>19) return NULL;    int i=strlen(tmp)-1,c;
        char *srcPtr=tmp,*dstPtr=result;
        bool bPrevZero=false;
        for(; *srcPtr; srcPtr++,i--) {
         if(*srcPtr=='.') continue;
            c=*srcPtr-'0';
    if(c!=0) {
             strcpy(dstPtr,CCC[c]); dstPtr+=2;
                if(srcPtr==tmp && c==1 && strcmp(QQQ[i],"拾")==0) dstPtr-=2;
            strcpy(dstPtr,QQQ[i]);  dstPtr+=2;
                bPrevZero=false;
                continue;
            }        if(bPrevZero) {
             if(strcmp(QQQ[i],"圆")==0 || strcmp(QQQ[i],"万")==0 || strcmp(QQQ[i],"亿")==0) {
                 dstPtr-=2; *dstPtr=0;
                 if(strcmp(dstPtr-2,"亿")) {strcpy(dstPtr,QQQ[i]); dstPtr+=2;}
                    bPrevZero=false;
                }
            } else {
             if(strcmp(QQQ[i],"圆") && strcmp(QQQ[i],"万") && strcmp(QQQ[i],"亿")) {
    strcpy(dstPtr,"零"); dstPtr+=2;
                    bPrevZero=true;
                }else {
                 strcpy(dstPtr,QQQ[i]);  dstPtr+=2;
                    bPrevZero=false;
                }
    }
        }    i=strlen(result);
        if(strcmp(result+i-2,"零")==0) result[i-2]=0;
        tmp[0]=result[0]; tmp[1]=result[1]; tmp[2]=0;
        if(strcmp(tmp,"圆")==0) {
            if(result[2]==0) strcpy(result,"零圆");
            else {
             tmp[0]=result[2]; tmp[1]=result[3]; tmp[2]=0;
                return strcmp(tmp,"零")==0 ? result+4 : result+2 ;
            }
        }
        return result;
    }
      

  3.   

    需要改动:
    1、CString bit[] = {"万","拾","佰","仟","亿",""};
    2、if ( j== 0 ) x = bit[5];
    else if ( j == 8) x = bit[4];
    else x = bit[j%4];
    3、double f  = 1234567890.25;