C++ 的string 与java的String中的汉字长度
2010-10-29 17:14
190 查看
Code:
public class Example
{
public Example(double x)
{
String yuan="亿千百拾万千百十元角分";
String digit="零壹贰叁肆伍陆柒捌玖";
String str="";
int y=(int)Math.round(x*100-0.5);//123414
int i=yuan.length()-1;
while(y>0&&i>0)
{
str=""+digit.charAt(y%10)+yuan.charAt(i)+str;
i--;
y=y/10;
}
System.out.println(str); //壹千贰百叁十肆元壹角肆分
}
public static void main(String[] args)
{
new Example(1234.14);
}
}
Code:
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Money
{
public:
string M(string original)
{
static string yuan="亿千百拾万千百十元角分";
static string digit="零壹贰叁肆伍陆柒捌玖";
long double b;
b=strtod(&original[0],NULL);
int n=int(100*b);//123414
int v=0;
int i=yuan.length()-1;//21
string str="";
while(i>0&&n>0)
{
v=n%10;
str=yuan[i]+str;
str=yuan[i-1]+str;
str=digit[2*v+1]+str;
str=digit[2*v]+str;
i=i-2;
n=n/10;
}
return str;
};
};
int _tmain(int argc, _TCHAR* argv[])
{
Money T;
cout<<T.M("1234.14");
return 0;
}
public class Example
{
public Example(double x)
{
String yuan="亿千百拾万千百十元角分";
String digit="零壹贰叁肆伍陆柒捌玖";
String str="";
int y=(int)Math.round(x*100-0.5);//123414
int i=yuan.length()-1;
while(y>0&&i>0)
{
str=""+digit.charAt(y%10)+yuan.charAt(i)+str;
i--;
y=y/10;
}
System.out.println(str); //壹千贰百叁十肆元壹角肆分
}
public static void main(String[] args)
{
new Example(1234.14);
}
}
Code:
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Money
{
public:
string M(string original)
{
static string yuan="亿千百拾万千百十元角分";
static string digit="零壹贰叁肆伍陆柒捌玖";
long double b;
b=strtod(&original[0],NULL);
int n=int(100*b);//123414
int v=0;
int i=yuan.length()-1;//21
string str="";
while(i>0&&n>0)
{
v=n%10;
str=yuan[i]+str;
str=yuan[i-1]+str;
str=digit[2*v+1]+str;
str=digit[2*v]+str;
i=i-2;
n=n/10;
}
return str;
};
};
int _tmain(int argc, _TCHAR* argv[])
{
Money T;
cout<<T.M("1234.14");
return 0;
}
相关文章推荐
- 一个中文汉字算两位,一个英文字母算一位,计算中文和英文混合的字符串长度。字符串:String str = "我不好java";
- 一个中文汉字算两位,一个英文字母算一位,计算中文和英文混合的字符串长度。字符串:String str = "我不好java";
- java String 中length()的长度计算,substring(0,n);的截取长度计算
- java中的String.split() 中“|”作为分隔符的问题和数组长度问题
- 【关于String的Demo_01】获取带有汉字的字符串的长度,汉字为2位
- C++ 数组与字符串长度sizeof()、strlen()、string的length()和size()
- JNI学习--Java和C、C++之间的数据类型映射之string
- JNI+opencv3+.dll+eclipse+vs2015:java调用c++传递String类型参数全过程
- java 之Sting类型的List集合的汉字排序和String类型数组的汉字排序及List<Bean>排序
- Java和JS中String、数组长度的求法
- java中基本数据类型和String类型的字节长度
- c++ 判断字符串只包含字母、数字、汉字 bool StringUtils::CheckName(const char * iName){ bool result=false; if(strle
- JNI学习笔记 C++传递结构体、String、数组对象给JavaC++传递结构体、String、数组对象给Java
- java中String类型的最大长度
- java 如何将byte中的有效长度转换为String
- C++判断string是不是数字|C++获取数组长度
- JAVA 的 可变长度的 方法的 参数 比如 String...arg
- C++/JAVA基本数据类型长度
- java判断String是否为汉字
- C++快速实现String到int int到String 转换 JAVA