/** * @(#)RMB.java * * RMB application * * @author * @version 1.00 2013/3/20 */ /** * @(#)RMB.java * * RMB application * * @author * @version 1.00 2013/3/20 */ import javax.swing.*; public class RMB { public static String toString(double x) //将x表示的金额转换成中文大写形式 { String yuan="亿千百拾万千百拾元角分"; String digit="零壹贰叁肆伍陆柒捌玖"; //字符串长度digit.length()为10 String result=""; int y=(int)(x*100); int i=yuan.length()-1; boolean flag = true; while(y > 0) { if(y == 1000) { result = "拾元整"+result; y = 0; } else { if(y%100 == 0 && i == yuan.length()-1) { result = "" + "整" +result; i = i - 2; y = y / 100; } else { if(y%10 == 0 && flag) { result = "" + digit.charAt(0) + result; flag = false; i --; y = y / 10; } else { if(y%10==0 && !flag) { i --; y = y / 10; } else if(y%10 != 0) { result = ""+digit.charAt(y%10)+yuan.charAt(i)+result; i --; y = y / 10; } } } } } return result; } public static void main(String args[]) { double x; x = Double.parseDouble(JOptionPane.showInputDialog("请输入存款金额:")); JOptionPane.showMessageDialog(null,RMB.toString(x),"你存入帐户的金额是:",1); } }