怎样用C/C++ 把[人民币数字]转化成[人民币大写]

isoftman 2005-11-23 02:56:40

对一给定字符串,如:1234.55,转换成正确的中文货币描述:
如:人民币壹仟贰佰叁拾四元五角五分
...全文
586 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shipotianjing 2005-11-23
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;

void main()
{
double RMB;
cout<<"Please input the numbers of RMB:\n";
cout.setf(ios_base::showpoint);
cout.setf(ios_base::fixed,ios_base::floatfield);
cout.precision(2);
cin>>RMB;
int a=1,b,i=0,s[20];
b=(int)(RMB*100);
while(b!=0)
{
s[i]=b%10;
i++;
b=b/10;
}
int *p=new int[i];
for(int j=i-1;j>=0;j--)
{
p[i-1-j]=s[j];
}
for(int m=0;m<i;m++)
{
cout<<p[m]<<" ";
}
return;
}

只是从高位到低位顺序输出各位数字,不完整,还望高人指点.
whizstorm 2005-11-23
  • 打赏
  • 举报
回复
char* itoa_( int ii_source, char* &opc_dest, int& oi_dest)
{//itoa调用该函数后要释放函数中动态分配的空间
int i = 0, ti_source = ii_source;
for( ; ; )//得到位数即字符数目
{
if ( (ti_source /= 10) != 0 )
{
++oi_dest;
continue;
}
++oi_dest;
break;
}
opc_dest = (char*)malloc(oi_dest*sizeof(char));
if( ii_source >= 0 )//负数处理
ti_source = ii_source;
else
ti_source = -ii_source;
for( i = 0; i < oi_dest; ++i ) //处理字符数
{
opc_dest[oi_dest-i-1] = ti_source%10;
ti_source /= 10;
}
if( ii_source < 0 )//处理下负数
opc_dest[0] = -opc_dest[0];
return opc_dest;//返回地址需要释放
}
whizstorm 2005-11-23
  • 打赏
  • 举报
回复
很简单,参照函数 itoa()
lukeguo 2005-11-23
  • 打赏
  • 举报
回复
1、将数字转化为字符串,然后逐位翻译成汉字(‘0’-> "零",'1'-> "壹",...),并加单位(拾、佰、仟、万),零不加。

2、标准化处理:如1008直接翻译为壹千零零捌元,但正确为壹千零零捌元整。

自己再琢磨一下吧,还有几个地方要处理。

65,189

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧