Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1798889
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类: C/C++

2008-11-18 10:32:04

money2HZ(money,length,big)
double  money;
int *length;
char    *big;
{
    static  char    str[61];
    char    buf[16],power[3];
    int i,position,flag0;
    position = 0;
    sprintf(buf,"%15.2f",money);
    for(i = 0; i < 60; i++)
        str[i] = ' ';
    str[60] = NULL;
    for(i = 0; buf[i] == ' '; i++)
        ;
    while(i <= 14)
    {
        flag0 = TRUE;
        switch(i)
        {
            case 0: case 4: case 8:
                sprintf(power,"仟");
                break;
            case 1: case 5: case 9:
                sprintf(power,"佰");
                break;
            case 2: case 6: case 10:
                sprintf(power,"拾");
                break;
            case 3:
                sprintf(power,"亿");
                if(buf[i] == '0')
                {
                    str[position] = power[0];
                    str[position+1] = power[1];
                    position += 2;
                    goto    next;
                }
                break;
            case 7:
                sprintf(power,"万");
                if(buf[i] == '0' && buf[i-1] == '0' && buf[i-2] == '0' && buf[i-3] == '0')
                {
                    goto    next;
                }
                if(buf[i] == '0')
                {
                    str[position] = power[0];
                    str[position+1] = power[1];
                    position += 2;
                    goto    next;
                }
                break;
            case 11:
         sprintf(power,"元");
                if(buf[i] == '0' && position != 0)
                {
                    str[position] = power[0];
                    str[position+1] = power[1];
                    position += 2;
                    goto    next;
                }
                if(buf[i] == '0' && position == 0)
                {
                    sprintf(power,"零");
                    str[position] = power[0];
                    str[position+1] = power[1];
                    sprintf(power,"元");
                    str[position+2] = power[0];
                    str[position+3] = power[1];
                    position += 4;
                    goto    next;
                }
                break;
            case 12:
                flag0 = FALSE;
                if(buf[i+1] == '0' && buf[i+2]=='0')
                {
                    sprintf(power,"整");
                    str[position] = power[0];
                    str[position+1] = power[1];
                    position += 2;
                    goto    outloop;
                }
                break;
            case 13:
                sprintf(power,"角");
                if(position == 4)
                {
                    if(buf[i-2] == '0')
                    {
                        position=0;
                        str[position] = '\0';
                        if(buf[i] == '0')
                            goto    next;
                    }
                }
                break;
            case 14:
                if(buf[i] == '0')
                    goto    outloop;
                sprintf(power,"分");
                break;
        }
        if(flag0 == TRUE)
        {
            if(i > 0)
              position += join(str,power,buf[i],buf[i+1],position);
            else
                position += join(str,power,buf[i],buf[i],position);
        }
    next:
        i++;
    }
outloop:
    str[position] = NULL;
    if(length != (int *)NULL)
        *length = position;
    strcpy(big,str);
    return(TRUE);
}
阅读(1366) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~