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) |