C语言 浮点数转换为字符串
#include<stdio.h>#include<stdlib.h>#include<string.h>charc_je[51];char*zh(doublex)/*数...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char c_je[51];
char* zh(double x ) /*数字金额转换为大写金额子程序*/
{
int i,n,bz;
char je[14];
char temp[13];
char f1[10][3]={"零","壹","贰","叁","肆","伍",
"陆","柒","捌","玖"}; /*数字对应的大写数组变量*/
char f2[11][3]={"亿","仟","佰","拾","万",
"仟","佰","拾","元","角","分"}; /*每位数字对应单位数组变量*/
sprintf(je,"%.01f",100*x);
n=strlen(je);
//printf("%d GGGGG",n);
c_je[0]='\0';
bz=1;
for(i=0;i<n;i++)
{
strcpy(temp,&je[i]);
if(atoi(temp)==0)
{
bz=2;
if(i==0)
strcat(c_je,f1[0]);
break;
}
if(je[i]!='0')
{
if(bz==0)
strcat(c_je,f1[0]);
//printf("%s ++++",f1[je[i]-'0']);
strcat(c_je,f1[je[i]-'0']);
bz=1;
strcat(c_je,f2[13-n+i]);
}
else
{
if(n-i==7&&(je[i-1]!='0'||je[i-2]!='0'||je[i-3]!='0'))
strcat(c_je,"万");
if(n-i==3)
strcat(c_je,"元");
bz=0;
}
}
if(bz==2)
{
if(n-i>=7 && n-i<10)
strcat(c_je,"万");
if(n-i>=3)
strcat(c_je,"元");
strcat(c_je,"正");
}
return c_je;
}
main()
{
zh(1234.56);
}
请问 strcat(c_je,f1[je[i]-'0']);里面f1[je[i]-'0']为什么要-‘0’ je[i]-'0'是什么意思 展开
#include <stdlib.h>
#include <string.h>
char c_je[51];
char* zh(double x ) /*数字金额转换为大写金额子程序*/
{
int i,n,bz;
char je[14];
char temp[13];
char f1[10][3]={"零","壹","贰","叁","肆","伍",
"陆","柒","捌","玖"}; /*数字对应的大写数组变量*/
char f2[11][3]={"亿","仟","佰","拾","万",
"仟","佰","拾","元","角","分"}; /*每位数字对应单位数组变量*/
sprintf(je,"%.01f",100*x);
n=strlen(je);
//printf("%d GGGGG",n);
c_je[0]='\0';
bz=1;
for(i=0;i<n;i++)
{
strcpy(temp,&je[i]);
if(atoi(temp)==0)
{
bz=2;
if(i==0)
strcat(c_je,f1[0]);
break;
}
if(je[i]!='0')
{
if(bz==0)
strcat(c_je,f1[0]);
//printf("%s ++++",f1[je[i]-'0']);
strcat(c_je,f1[je[i]-'0']);
bz=1;
strcat(c_je,f2[13-n+i]);
}
else
{
if(n-i==7&&(je[i-1]!='0'||je[i-2]!='0'||je[i-3]!='0'))
strcat(c_je,"万");
if(n-i==3)
strcat(c_je,"元");
bz=0;
}
}
if(bz==2)
{
if(n-i>=7 && n-i<10)
strcat(c_je,"万");
if(n-i>=3)
strcat(c_je,"元");
strcat(c_je,"正");
}
return c_je;
}
main()
{
zh(1234.56);
}
请问 strcat(c_je,f1[je[i]-'0']);里面f1[je[i]-'0']为什么要-‘0’ je[i]-'0'是什么意思 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询