package test;
import java.math.BigDecimal;
public class Convert {
static BigDecimal MAXIMUM_NUMBER = new BigDecimal("999999999999.99");
static String CN_ZERO = "零";
static String CN_ONE = "壹";
static String CN_TWO = "贰";
static String CN_THREE = "叁";
static String CN_FOUR = "肆";
static String CN_FIVE = "伍";
static String CN_SIX = "陆";
static String CN_SEVEN = "柒";
static String CN_EIGHT = "捌";
static String CN_NINE = "玖";
static String CN_TEN = "拾";
static String CN_HUNDRED = "佰";
static String CN_THOUSAND = "仟";
static String CN_TEN_THOUSAND = "万";
static String CN_HUNDRED_MILLION = "亿";
static String CN_SYMBOL = "";
static String CN_DOLLAR = "元";
static String CN_TEN_CENT = "角";
static String CN_CENT = "分";
static String CN_INTEGER = "整";
static String integral;
static String decimal;
static String outputCharacters;
static String[] parts = new String[2];
static String[] digits, radices, bigRadices, decimals;
static int zeroCount;
static int i, p;
static int d, ds;
static int quotient, modulus;
public static void main(String[] args) {
System.out.println("star");
System.out.println(conver(new BigDecimal("100300.99")));
System.out.println("end");
}
public static String conver(BigDecimal price) {
String currencyDigits = price.toString();
if (currencyDigits == "") {
return "";
}
currencyDigits = currencyDigits.replace("/,/g", "");
currencyDigits = currencyDigits.replace("/^0+/", "");
if ((MAXIMUM_NUMBER.compareTo(new BigDecimal(currencyDigits))) < 0) {
return "";
}
String[] parts = currencyDigits.split("\\.");
if (parts.length > 1) {
integral = parts[0];
decimal = parts[1];
decimal = decimal.substring(0, 2);
} else {
integral = parts[0];
decimal = "";
}
digits = new String[] { CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT,
CN_NINE };
radices = new String[] { "", CN_TEN, CN_HUNDRED, CN_THOUSAND };
bigRadices = new String[] { "", CN_TEN_THOUSAND, CN_HUNDRED_MILLION };
decimals = new String[] { CN_TEN_CENT, CN_CENT };
outputCharacters = "";
if (new BigDecimal(integral).compareTo(new BigDecimal(0)) > 0) {
zeroCount = 0;
for (int i = 0; i < integral.length(); i++) {
p = integral.length() - i - 1;
d = Integer.parseInt(integral.substring(i, i + 1));
//控制万以上
quotient = p / 4;
//4以内是百千
modulus = p % 4;
if (d == 0) {
zeroCount++;
} else {
if (zeroCount > 0) {
outputCharacters += digits[0];
}
zeroCount = 0;
outputCharacters += digits[d] + radices[modulus];
}
if (modulus == 0 && zeroCount < 4) {
outputCharacters += bigRadices[quotient];
zeroCount = 0;
}
}
outputCharacters += CN_DOLLAR;
}
if (decimal != "") {
for (i = 0; i < decimal.length(); i++) {
d = Integer.parseInt(decimal.substring(i, i + 1));
if (d != 0) {
outputCharacters += digits[d] + decimals[i];
}
}
}
if (outputCharacters == "") {
outputCharacters = CN_ZERO + CN_DOLLAR;
}
if (decimal == "") {
outputCharacters += CN_INTEGER;
}
outputCharacters = CN_SYMBOL + outputCharacters;
return outputCharacters;
}
}