标签:java钱币转换、钱币转换、转换、钱币、钱转为人民币大写
import java.text.DecimalFormat; public class ChangeMonney { private static final String[] STR_UNIT = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; private static final String[] STR_NUMBER = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟"}; public static void main(String[] args) { // TODO Auto-generated method stub double d = 1234567; System.out.print(convert(d)); } //钱币转换 public static String convert(double d) { DecimalFormat dFormat = new DecimalFormat("#0.###"); String Num = dFormat.format(d); if (Num.indexOf(".")!=-1) { String strNum = Num.substring(0,Num.indexOf(".")); if(strNum.length()>12) System.out.println("数字太大了,不能完成转换"); } String point = ""; if(Num.indexOf(".")!=-1) { point ="元"; } else point ="元整"; String result = getInter(Num); return result; } public static String getInter(String Num) { //判断是否含有小数点 if (Num.indexOf(".")!=-1) { Num = Num.substring(0,Num.indexOf(".")); } Num = new StringBuffer(Num).reverse().toString(); StringBuffer temp = new StringBuffer(); for (int i = 0; i < Num.length(); i++) { temp.append(STR_NUMBER[i]); temp.append(STR_UNIT[Num.charAt(i)-48]); } Num = temp.reverse().toString(); Num = Num.replace("零拾", "零"); Num = Num.replace("零佰", "零"); Num = Num.replace("零仟", "零"); Num = Num.replace("零万", "零"); Num = Num.replace("零亿", "零"); return Num; } }
本文出自 “风雨兼程” 博客,请务必保留此出处http://carben.blog.51cto.com/8690350/1643544
标签:java钱币转换、钱币转换、转换、钱币、钱转为人民币大写
原文地址:http://carben.blog.51cto.com/8690350/1643544