这是我的第一篇文章。
使用java实现的,中文财务读取金额方式。如:12345读作“壹万贰仟叁拾肆元整”。
一般拿到一个数字,首先看是否存在小数,然后按照整数部分和小数部分分别读取,然后组合成最终的结果。
实现过程已经参考了财务读取金额的教程,如有错误,欢迎指正。
下面是源代码:
/**
* 目前支持千万亿级别两位小数的读取
* @author Renqiang_cheng
*
*/
public class ReadMoney {
private static final String[] NUM_READ = { "零", "壹", "贰", "叁", "肆", "伍",
"陆", "柒", "捌", "玖" };//读取的数字
private static final String[] UNIT_READ = { "", "拾", "佰", "仟", "万", "拾",
"佰", "仟", "亿", "拾", "佰", "仟", "万" };//各个数位
private static final String[] CLASS_READ = { "元", "角", "分" };//单位
private static final String[] SPECIAL_READ = { "整" };//特殊字符
public static void main(String[] args) {
System.out.println(getReadInChinese("1234567891234"));
System.out.println(getReadInChinese("1234567891234.00"));
System.out.println(getReadInChinese("891234.05"));
System.out.println(getReadInChinese("891234.58"));
System.out.println(getReadInChinese("891234.80"));
System.out.println(getReadInChinese("891230.58"));
System.out.println(getReadInChinese("891200.58"));