C++ 的string 与java的String中的汉字长度

Code:
  1. public class Example   
  2. {   
  3.     public Example(double x)  
  4.     {  
  5.         String yuan="亿千百拾万千百十元角分";  
  6.         String digit="零壹贰叁肆伍陆柒捌玖";  
  7.         String str="";  
  8.         int y=(int)Math.round(x*100-0.5);//123414  
  9.         int i=yuan.length()-1;  
  10.         while(y>0&&i>0)  
  11.         {  
  12.             str=""+digit.charAt(y%10)+yuan.charAt(i)+str;  
  13.             i--;  
  14.             y=y/10;  
  15.         }  
  16.         System.out.println(str); //壹千贰百叁十肆元壹角肆分  
  17.     }  
  18.     public static void main(String[] args)  
  19.     {    
  20.         new Example(1234.14);  
  21.     }     
  22. }  
Code:
  1. #include "stdafx.h"  
  2. #include <iostream>  
  3. #include <cstring>  
  4. #include <string>  
  5. #include <algorithm>  
  6. #include <vector>  
  7. using namespace std;  
  8. class Money  
  9.     {  
  10.     public:  
  11.         string M(string original)  
  12.             {  
  13.         static string yuan="亿千百拾万千百十元角分";  
  14.         static string digit="零壹贰叁肆伍陆柒捌玖";  
  15.     long double b;  
  16.     b=strtod(&original[0],NULL);  
  17.     int n=int(100*b);//123414  
  18.     
  19.     int v=0;  
  20.     int i=yuan.length()-1;//21  
  21.     string str="";         
  22.                 while(i>0&&n>0)  
  23.                     {  
  24.                     v=n%10;  
  25.                     str=yuan[i]+str;  
  26.                     str=yuan[i-1]+str;  
  27.   
  28.                     str=digit[2*v+1]+str;  
  29.                     str=digit[2*v]+str;  
  30.   
  31.   
  32.                     i=i-2;  
  33.                     n=n/10;  
  34.                     }  
  35.             return str;  
  36.             };  
  37.     };  
  38.   
  39. int _tmain(int argc, _TCHAR* argv[])  
  40. {  
  41.     Money T;   
  42.     cout<<T.M("1234.14");  
  43.     return 0;  
  44. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值