正文

人民币大小写转换的程序2007-04-15 14:00:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/goal00001111/24906.html

分享到:

原来写过一个,但是有BUG,现在贴一个新的

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main(void)
{
    double money;
    char pZH[40];
    puts("输入一个数:");
    scanf("%lf", &money);
    double ZH = floor(money);
    gcvt(ZH, 35, pZH);

    char *num[10] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
    char *RMB[] ={"圆","拾","佰","仟","萬","拾","佰","仟","億", "十", "百", "千", "万", "億"};
    int n = 0;           
    while (pZH[n] != '.')
        n++; 
    n--;
//输出整数部分
    puts("你输入了:");
    int flag = 0;
    int i;
    for (i=0; pZH[i]!='.'; i++, n--)
    {
        if (pZH[i] == '0')//出现多个0时,并非输出所有的"零"
        {//"亿"和"万"要特殊处理
            if (n==8 || n==4 && ((i>=1&&pZH[i-1]!='0')|| (i>=2&&pZH[i-2]!='0')||(i>=3&&pZH[i-3]!='0')))
                printf("%s", RMB[n]);
           
            flag = 1;
            continue;
        }
       
        if (flag == 1)
            printf("零");
           
        printf("%s%s", num[pZH[i]-'0'], RMB[n]);
        flag = 0;
    }
//输出小数部分
    char *unit[4] = {"角", "分", "厘", "毫"};
    char pXH[6];
    double XH = floor((money-ZH)*10000) ;//不四舍五入了,让银行吃点亏
    gcvt(XH, 6, pXH);
   
    for (i=0; i<4; i++)
        printf("%s%s", num[pXH[i]-'0'], unit[i]);   
    printf("\n");  
 
       
       system("pause");
       return 0;
}

阅读(2277) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册