日期:2014-05-20  浏览次数:20751 次

金额的中文大写形式
/*
 * MoneyChange.java
 *
 * Created on 2007年10月1日, 下午2:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *程序目的:金额的中文大写形式 //10005.56这些情况没实现~请高手帮忙了~
 *形式:作业
 * @author luzhide
 */
public class MoneyChange {
  private String data[]={"","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; 
  private String money_zheng[]={"亿","千","百","拾","万","千","百","拾",""};
  private String money_small[]={"角","分"};
  private String MoneyToZheng(int zheng) //处理整数部分(算法不全,正在改进中)
  {
  String str_z1="";
  String str_z2="";
  String str_zheng="";
  int j=money_zheng.length-1;
  while(zheng>0&&j>0)
  {
  if(zheng%10==0)
  {
  str_zheng=""+str_zheng;
  }
  else
  {
  str_z1=data[zheng%10];
  str_z2=money_zheng[j];
  str_zheng=""+str_z1+str_z2+str_zheng;
  }
  zheng=zheng/10;
  j--;
  }
   
  return str_zheng+"元";
  }
  private String MoneyToSmall(int small) //对小数部分进行转换
  {
  String str1="",str2="";
  String strSmall="";
  int i=money_small.length-1;
  if(small>=10)
  {
  while(small>0&&i>=0)
  {
   
  if(small%10!=0)
  {
  str1=data[small%10];
  str2=money_small;
  strSmall=""+str1+str2+strSmall;
  }
   
  small=small/10;
  i=i-1;
  }
  }
  else
  {
  if(small!=0)
  {
  strSmall+=data[small]+money_small[1];
  }
  }
  return strSmall;
  }
  private String MoneyToChange(double number)
  {
  String strAll,str_int,str_sma,str_z;
  strAll="";str_int="";str_sma="";str_z="";
  int int_zheng,int_small;//
  //四舍五入 
  number=(number*100+0.5)/100; 
   
  int_zheng=(int)(number*100/100);//整数部分
  if(int_zheng!=0)
  {
  str_int=MoneyToZheng(int_zheng);
  }
  //小数部分 
  double temp=(number-int_zheng)*100*100/100; 
  //对小数部分四舍五入 
  int_small=(int)(temp*100+0.5)/100;
  if(int_small!=0)
  {
  str_sma=MoneyToSmall(int_small);
  }
  else
  {
  str_z="整";
  }
  strAll=str_int+str_sma+str_z;
  return strAll;
   
  }
  public static void main(String args[])