大小寫 中文轉換

          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 閱讀(987) 評論(0)  編輯  收藏 所屬分類: java

          導航

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統計

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案(17)

          文章分類(86)

          收藏夾(3)

          flex blog

          good site

          java blog

          my friend

          tools

          抓蝦

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 隆安县| 明溪县| 皋兰县| 金川县| 阿拉善盟| 深水埗区| 曲阜市| 三原县| 清镇市| 玛纳斯县| 沁水县| 彰化县| 定结县| 龙陵县| 安乡县| 八宿县| 上饶市| 苏尼特左旗| 六安市| 古交市| 衡南县| 牙克石市| 会宁县| 郯城县| 新营市| 五常市| 孟津县| 甘肃省| 平顺县| 阿拉尔市| 和龙市| 石狮市| 炎陵县| 同德县| 太谷县| 阜康市| 永仁县| 孝昌县| 县级市| 重庆市| 方山县|