此代碼根據網上搜集到的部分代碼進行修改
package PrintOperate;
import java
import java
public class SimpleMoneyFormat
public static final String EMPTY =
public static final String ZERO =
public static final String ONE =
public static final String TWO =
public static final String THREE =
public static final String FOUR =
public static final String FIVE =
public static final String SIX =
public static final String SEVEN =
public static final String EIGHT =
public static final String NINE =
public static final String TEN =
public static final String HUNDRED =
public static final String THOUSAND =
public static final String TEN_THOUSAND =
public static final String HUNDRED_MILLION =
public static final String YUAN =
public static final String JIAO =
public static final String FEN =
public static final String DOT =
private static SimpleMoneyFormat formatter = null;
private HashMap chineseNumberMap = new HashMap();
private HashMap chineseMoneyPattern = new HashMap();
private NumberFormat numberFormat = NumberFormat
private SimpleMoneyFormat()
numberFormat
numberFormat
numberFormat
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseNumberMap
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
chineseMoneyPattern
}
public static SimpleMoneyFormat getInstance()
if (formatter == null)
formatter = new SimpleMoneyFormat();
}
return formatter;
}
public String format(String moneyStr)
checkPrecision(moneyStr);
String result;
result = convertToChineseNumber(moneyStr);
result = addUnitsToChineseMoneyString(result);
return result;
}
public String format(double moneyDouble)
return format(numberFormat
}
public String format(int moneyInt)
return format(numberFormat
}
public String format(long moneyLong)
return format(numberFormat
}
public String format(Number moneyNum)
return format(numberFormat
}
private String convertToChineseNumber(String moneyStr)
String result;
StringBuffer cMoneyStringBuffer = new StringBuffer();
for (int i =
cMoneyStringBuffer
}
//拾佰仟萬億等都是漢字裡面才有的單位
int indexOfDot = cMoneyStringBuffer
int moneyPatternCursor =
for (int i = indexOfDot
cMoneyStringBuffer
moneyPatternCursor = moneyPatternCursor ==
}
String fractionPart = cMoneyStringBuffer
cMoneyStringBuffer
while (cMoneyStringBuffer
cMoneyStringBuffer
}
while (cMoneyStringBuffer
cMoneyStringBuffer
}
while (cMoneyStringBuffer
cMoneyStringBuffer
}
while (cMoneyStringBuffer
cMoneyStringBuffer
}
while (cMoneyStringBuffer
cMoneyStringBuffer
}
while (cMoneyStringBuffer
cMoneyStringBuffer
}
if (cMoneyStringBuffer
cMoneyStringBuffer
}
cMoneyStringBuffer
result = cMoneyStringBuffer
return result;
}
private String addUnitsToChineseMoneyString(String moneyStr)
String result;
StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr);
int indexOfDot = cMoneyStringBuffer
cMoneyStringBuffer
cMoneyStringBuffer
cMoneyStringBuffer
if (cMoneyStringBuffer
cMoneyStringBuffer
}
else if (cMoneyStringBuffer
cMoneyStringBuffer
}
else if (cMoneyStringBuffer
if(cMoneyStringBuffer
cMoneyStringBuffer
}
else
cMoneyStringBuffer
}
}
result = cMoneyStringBuffer
return result;
}
private void checkPrecision(String moneyStr)
int fractionDigits = moneyStr
if (fractionDigits >
throw new RuntimeException(
}
}
public static void main(String args[])
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26854.html