package com.scylla.test;
public class ChangeMo
{
static String num1[] = {"零", "壹", "貳", "三", "肆", "伍", "陸","柒","捌","玖",};
public static void main(String [] args)
{
String input = "1234567891234567.89";
String tem [] = input.split("\\.");
String int_str = toChineseDigit(tem[0])+"元";
int mao = Integer.parseInt(tem[1])/10;
int fen = Integer.parseInt(tem[1])%10;
String mao_s = num1[mao]+"毛";
String fen_s = num1[fen]+"分";
if(mao==0)
{
mao_s = "零";
}
if(fen==0)
{
fen_s = "";
}
if(mao==0&&fen==0)
{
mao_s = "";
fen_s = "";
}
String dec_str = mao_s+fen_s;
String all = int_str+dec_str;
System.out.println(all);
}
public static String toChineseDigit(String n)
{
String num2[] = {"", "拾", "佰", "仟", "萬", "億", "兆", "吉", "太", "拍", "艾"};
int len = n.length();
//
if (len <= 5)
{
String ret = "";
for (int i = 0; i < len; i++)
{
if (n.charAt(i) == '0')
{
int j = i + 1; //用来判断0后面一位是不是0
//如果0后面一位不是0,则j不会++,则i的值沒有变化(即i=i+1-1)
//如果0后面也是0,后面有连续的n个0,则j++ n次,i也++ n次(即i要跳过n位)
while (j < len && n.charAt(j) == '0')
++j;
if (j < len)
ret += "零";
i = j - 1;
}
else
ret = ret + num1[Integer.parseInt(n.substring(i, i + 1))] + num2[len - i - 1];
}
return ret;
}
else if (len <= 8)
{
String ret = toChineseDigit(n.substring(0, len - 4)); //先得到万级的数字
if (ret.length() != 0)
ret += num2[4]; //帶上单位 '萬'
return ret + toChineseDigit(n.substring(len - 4)); //再得到万级后面的数字
}
else
{
String ret = toChineseDigit(n.substring(0, len - 8)); //先得到亿级的数字
if (ret.length() != 0)
ret += num2[5]; //帶上單位 '亿'
return ret + toChineseDigit(n.substring(len - 8)); //再得到亿级后面的数字
}
}
}
壹仟貳佰三拾肆萬伍仟陸佰柒拾捌億玖仟壹佰貳拾三萬肆仟伍佰陸拾柒元捌毛玖分