大小写 中文转换

public class Test {
 /*
  *  <p>Description: 字符串处理的公共类</p>
  *  <p>Copyright 2006 </p>
  *  @author  leonards
  *  @Create Date : 2006-11-23
  */

 /*
  *  将字符串转换成中文的大写货币值
  *  @param   moneyStr
  *  @return
  */
 public static String convertToCapitalMoney(String moneyStr) {
  double money = 0;
  try {
   money = Double.parseDouble(moneyStr);
  } catch (Exception e) {

  }
  return convertToCapitalMoney(money);
 }

 /*
  *  将数字转换成中文的大写货币值
  *  @param   moneyValue
  *  @return
  */
 public static String convertToCapitalMoney(double moneyValue) {
  double money = moneyValue + 0.005; //  防止浮点数四舍五入造成误差
  String Result = "";
  String capitalLetter = "零壹贰叁肆伍陆柒捌玖";
  String moneytaryUnit = "分角圆拾佰仟万拾佰仟亿拾佰仟万拾佰仟亿拾佰仟";
  String tempCapital, tempUnit;

  int integer; //  钱的整数部分
  int point; //  钱的小数部分
  int tempValue; //  钱的每一位的值
  integer = (int) money;
  point = (int) (100 * (money - (float) integer));

  if (integer == 0)
   Result = "零圆";
  /*
   *     货币整数部分操作
   *     1.    依次取得每一位上的值
   *     2.    转换成大写
   *     3.    确定货币单位
   */
  for (int i = 1; integer > 0; i++) {
   tempValue = (integer % 10);
   tempCapital = capitalLetter.substring(tempValue, tempValue + 1);
   tempUnit = moneytaryUnit.substring(i + 1, i + 2);
   Result = tempCapital + tempUnit + Result;
   integer = integer / 10;
  }
  /*
   *  货币小数部分操作
   */
  tempValue = (point / 10);
  for (int i = 1; i > -1; i--) {
   tempCapital = capitalLetter.substring(tempValue, tempValue + 1);
   tempUnit = moneytaryUnit.substring(i, i + 1);
   Result = Result + tempCapital + tempUnit;
   tempValue = point % 10;
  }
  return Result;
 }

 public static void main(String[] args) {

  String money1 = Test.convertToCapitalMoney("400000000.215");
  System.out.println(money1);
  String money = Test.convertToCapitalMoney(40000000.215);
  System.out.println(money);
 }

}

posted on 2007-04-23 16:23 leoli 阅读(971) 评论(0)  编辑  收藏 所属分类: java


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(6)

随笔分类

随笔档案(17)

文章分类(86)

收藏夹(3)

flex blog

good site

java blog

my friend

tools

抓虾

搜索

最新评论

阅读排行榜

评论排行榜