- 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);
- }
- }
- #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;
- }