#include<iostream>
using namespace std;
void Character(int digit,char*name)
{
switch(digit)
{
case 0:strcpy(name,"零");break;
case 1:strcpy(name,"壹");break;
case 2:strcpy(name,"贰");break;
case 3:strcpy(name,"叁");break;
case 4:strcpy(name,"肆");break;
case 5:strcpy(name,"伍");break;
case 6:strcpy(name,"陆");break;
case 7:strcpy(name,"柒");break;
case 8:strcpy(name,"捌");break;
case 9:strcpy(name,"玖");break;
}
};
void Convert(float num,char*description)//如果输入数据大于9999,另需以同样方式添加对万位的处理
{
short d;bool ZeroTag=false;
d=num/1000;//获得千位
if(d!=0)
{
char qianwei[3];
Character(d,qianwei);
strcpy(description,qianwei);
strcat(description,"仟");ZeroTag=false;
}
d=((int)num%1000)/100;//获得百位
if(d!=0)
{
char baiwei[3];
Character(d,baiwei);
strcat(description,baiwei);
strcat(description,"佰");ZeroTag=false;
}
else
{
if(((int)num)%100!=0)
strcat(description,"零");ZeroTag=true;
}
d=((int)num%100)/10;//获得十位
if(d!=0)
{
char shiwei[3];
Character(d,shiwei);
strcat(description,shiwei);
strcat(description,"拾");ZeroTag=false;
}
else
{
if((!ZeroTag)&&(((int)num)%10!=0))
{
strcat(description,"零");ZeroTag=true;
}
}
d=((int)num%10);//获得个位
if(d!=0)
{
char gewei[3];
Character(d,gewei);
strcat(description,gewei);
}
if((int)(num*100)%100!=0) strcat(description,"点");
else
{
strcat(description,"圆整");return;
}
d=((int)(num*10))%10;//十分位
if(d!=0)
{
char shifen[3];
Character(d,shifen);
strcat(description,shifen);
}
else strcat(description,"零");
d=((int)(num*100))%10;//百分位
if(d!=0)
{
char baifen[3];
Character(d,baifen);
strcat(description,baifen);
}
strcat(description,"圆");
};
int main()
{
char name[24];
Convert(6204.7,name);
cout<<name;
return 0;
}