axsoft
版主
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](http://earthday.link.org.tw/images/EARTHfinal.gif) 發表:681 回覆:1056 積分:969 註冊:2002-03-13
發送簡訊給我
|
金額數字轉換大寫函數 #include #define TEN "拾"
#define HND "佰"
#define THU "仟"
#define TTH "萬"
#define HMI "億" #define FILL(A) if(!zflag) \
strcat(sResult, A); \
break
#define FILLW(A) if(!zflag) \
{ \
tthflag = 1; \
strcat(sResult, A); \
} \
break #define FILLY(A) if(!zflag) \
{ \
hmiflag = 1; \
strcat(sResult, A); \
} \
break void main(int argc, char **argv)
{
if(argc < 2)
{
printf("Usage: %s amt\n", argv[0]);
exit(0);
}
PrintBigMoney(argv[1]); exit(0);
} int PrintBigMoney(char *source)
{
char sResult[300], intpart[30], decpart[20], *pstr;
char *BigNum[] = {"零","壹","貳","?","肆","伍","陸","柒","捌","玖"};
int i, intlen, p_int = 0, zheadflag = 1, zflag = 0;
int tthflag = 0, hmiflag = 0; memset(sResult, '\0', sizeof(sResult));
strcpy(intpart, source); if (intpart[p_int] == '-')
{
strcat(sResult, "負");
p_int ;
} pstr = (char *)strstr(intpart p_int, ".");
if (pstr != NULL)
{
pstr[0] = '\0';
strcpy(decpart, pstr 1);
}
intlen = strlen(intpart);
for(i = 0; i < intlen; i )
{
if(intpart[i] < '0' || intpart[i] > '9')
{
printf("part of int is not valid\n");
exit(0);
}
}
for(i = 0; i < strlen(decpart); i )
{
if(decpart[i] < '0' || decpart[i] > '9')
{
printf("part of dec is not valid\n");
exit(0);
}
}
if(intlen > 12)
printf("Warning: number is too large to translate, result is pos
sibly not accuracy!\n");
if(atol(intpart) == 0)
strcat(sResult, BigNum[0]);
for (i = p_int; i < intlen; i )
{
if (intpart[i] == '0')
{
if(zheadflag)
continue;
else
zflag = 1;
}
else
{
zheadflag = 0;
if(zflag)
{
strcat(sResult, BigNum[0]);
zflag = 0;
}
strcat(sResult, BigNum[intpart[i] - '0']);
}
switch(intlen - i)
{
case 2:
FILL(TEN);
case 6:
FILLW(TEN);
case 10:
FILLY(TEN);
case 14:
FILLW(TEN);
case 18:
FILLY(TEN);
case 3:
FILL(HND);
case 7:
FILLW(HND);
case 11:
FILLY(HND);
case 15:
FILLW(HND);
case 19:
FILLY(HND);
case 4:
FILL(THU);
case 8:
FILLW(THU);
case 12:
FILLY(THU);
case 16:
FILLW(THU);
case 20:
FILLY(THU);
case 5:
case 13:
if(!zflag)
strcat(sResult, TTH);
else
{
if(tthflag)
strcat(sResult, TTH);
}
break;
case 9:
tthflag = 0;
case 17:
strcat(sResult, HMI);
break;
}
}
strcat(sResult, "元");
if ((strlen(decpart) != 0) && (atol(decpart) != 0))
{
for (i = 0; i < strlen(decpart); i )
{
if (decpart[i] >= '0' && decpart[i] <= '9')
strcat(sResult, BigNum[decpart[i] - '0']);
if (i == 0)
strcat(sResult, "角");
if (i == 1)
strcat(sResult, "分");
}
}
else
strcat(sResult, "整");
printf("%s\n", sResult);
} 網路志工聯盟----Visita網站http://www.vista.org.tw
---[ 發問前請先找找舊文章 ]---
|