注:金额只到9999,9999,9999,9999 千万亿级别
import java.util.HashMap;
import java.util.Map;
public class MoneyUtil
{
public static Map<Integer,String> numMap = new HashMap<>();
public static Map<Integer,String> unitMap = new HashMap<>();
static {
numMap.put(0,"零");
numMap.put(1,"壹");
numMap.put(2,"贰");
numMap.put(3,"叁");
numMap.put(4,"肆");
numMap.put(5,"伍");
numMap.put(6,"陆");
numMap.put(7,"柒");
numMap.put(8,"捌");
numMap.put(9,"玖");
unitMap.put(2,"拾");
unitMap.put(3,"佰");
unitMap.put(4,"仟");
// unitMap.put(5,"萬");
unitMap.put(6,"拾");
unitMap.put(7,"佰");
unitMap.put(8,"仟");
// unitMap.put(9,"亿");
unitMap.put(10,"拾");
unitMap.put(11,"佰");
unitMap.put(12,"仟");
// unitMap.put(13,"萬");
unitMap.put(14,"拾");
unitMap.put(15,"佰");
unitMap.put(16,"仟");
}
/**
* 将输入的金额转成人民币大写
* @param momey
* @return
*/
public static String getUpperCaseMoney(long momey)
{
if (momey>0 && (momey+"").length()<=16)
{
String startNumStr = momey + "";
StringBuilder outPut = new StringBuilder();
char[] charArray = startNumStr.toCharArray();
for (int i=startNumStr.length()-1,k=1,j=1; i>=0 ; i--,k++,j++)
{
Integer num = Integer.parseInt(charArray[i]+"");
String numStr = numMap.get(num);
String unit = unitMap.get(j);
if (num==0)
{
if(k==5)
{
outPut.insert(0,"萬");
}
else if (k==9)
{
if (outPut.charAt(0)=='萬')
{
outPut.replace(0,1,"零");
}
outPut.insert(0,"亿");
}
else if (k==13)
{
outPut.insert(0,"萬");
}
if (outPut.length()>0)
{
if (outPut.charAt(0)!='零'&& outPut.charAt(0)!='萬' && outPut.charAt(0)!='亿')
{
outPut.insert(0,'零');
}
}
}
else
{
if(k==5)
{
outPut.insert(0,"萬");
}
else if (k==9)
{
if (outPut.charAt(0)=='萬')
{
outPut.replace(0,1,"零");
}
outPut.insert(0,"亿");
}
else if (k==13)
{
outPut.insert(0,"萬");
}
if (unit != null)
outPut.insert(0,numStr+unit);
else
outPut.insert(0,numStr);
}
}
System.out.println(outPut.toString());
return outPut.toString()+"圆整";
}
else
{
return "请输入长度小于16位的有效数字";
}
}
}