⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amtinwords_zh_tw.java

📁 大家共享愉快, 共享愉快, 共享愉快, 共享愉快,共享愉快
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2005 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.util;

import java.text.DecimalFormat;


/**
 *	Amount in Words for zh_TW
 *
 *  @author Jorg Janke - http://www.rgagnon.com/javadetails/java-0426.html
 *  @version $Id: AmtInWords_zh_TW.java,v 1.2 2005/04/19 04:43:31 jjanke Exp $
 */
public class AmtInWords_zh_TW implements AmtInWords {
    private final static DecimalFormat nf = new DecimalFormat("#####0.00");

    /**************************************************************************
     * 	Get Amount in Words
     * 	@param amount numeric amount (352.80)
     * 	@return amount in words (three*five*two 80/100)
     */
    public String getAmtInWords(String amount) throws Exception {
        if (amount == null)
            return amount;
        //
        int pos = amount.lastIndexOf('.');
        int pos2 = amount.lastIndexOf(',');
        if (pos2 > pos) {
            while (amount.indexOf('?') > 0) {
                amount = amount.substring(0, amount.indexOf('?')) +
                         amount.substring(amount.indexOf('?') + 1);
            } while (amount.indexOf('.') > 0) {
                amount = amount.substring(0, amount.indexOf('.')) +
                         amount.substring(amount.indexOf('.') + 1);
            }
            if (pos < 0) {
                amount = amount.replaceAll(",", ".");
            }
        } else {
            amount = amount.trim().replaceAll(",", "");
        }
        //
        String returnVal = "";
        String strUnit = "\u5146\u842c\u4edf\u4f70\u62fe\u5104\u4edf\u4f70\u62fe\u842c\u4edf\u4f70\u62fe\u5143\u89d2\u5206";
        String convertAmt = nf.format(Double.parseDouble(amount.replaceAll(" ",
                "")));
        convertAmt = convertAmt.substring(0, convertAmt.indexOf(".")) +
                     convertAmt.substring(convertAmt.indexOf(".") + 1);
        System.out.println("convertAmt: "+ convertAmt);
        strUnit = strUnit.substring(strUnit.length() - convertAmt.length());
        for (int i = 0; i < convertAmt.length(); i++) {
            returnVal +=
                    "\u96f6\u58f9\u8cb3\u53c3\u8086\u4f0d\u9678\u67d2\u634c\u7396".substring(Integer.parseInt(convertAmt.
                    substring(i, i + 1)),
                                           Integer.parseInt(convertAmt.
                    substring(i, i + 1)) +
                                           1) +
                    strUnit.substring(i, i + 1);
        }

        while (returnVal.indexOf("\u96f6\u5143") > 0 ||
               returnVal.indexOf("\u96f6\u62fe") > 0 ||
               returnVal.indexOf("\u96f6\u4f70") > 0 ||
               returnVal.indexOf("\u96f6\u4edf") > 0 ||
               returnVal.indexOf("\u96f6\u842c") > 0 ||
               returnVal.indexOf("\u96f6\u5104") > 0 ||
               returnVal.indexOf("\u96f6\u96f6") > 0 ||
               returnVal.indexOf("\u5104\u842c") > 0) {
            returnVal = replaceStr(returnVal, "\u96f6\u5143", "\u5143");
            returnVal = replaceStr(returnVal, "\u96f6\u62fe", "\u96f6");
            returnVal = replaceStr(returnVal, "\u96f6\u4f70", "\u96f6");
            returnVal = replaceStr(returnVal, "\u96f6\u4edf", "\u96f6");
            returnVal = replaceStr(returnVal, "\u96f6\u842c", "\u842c");
            returnVal = replaceStr(returnVal, "\u96f6\u5104", "\u5104");
            returnVal = replaceStr(returnVal, "\u96f6\u96f6", "\u96f6");
            returnVal = replaceStr(returnVal, "\u5104\u842c", "\u5104");
        }
        returnVal = replaceStr(returnVal, "\u96f6\u89d2\u96f6\u5206", "\u6574");
        returnVal = replaceStr(returnVal, "\u96f6\u5206", "");

        return returnVal;

    } //	getAmtInWords

    private static String replaceStr(String returnVal, String replaceStr,
                                     String replaceTo) {
        while (returnVal.indexOf(replaceStr) > 0) {
            returnVal = returnVal.substring(0, returnVal.indexOf(replaceStr)) +
                        replaceTo +
                        returnVal.substring(returnVal.indexOf(replaceStr) +
                                            replaceStr.length());
        }
        return returnVal;
    }
    /**
     * 	Test Print
     *	@param amt amount
     */
    private void print(String amt) {
        try {
            System.out.println(amt + " = " + getAmtInWords(amt));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } //	print

    /**
     * 	Test
     *	@param args ignored
     */
    public static void main(String[] args) {
        AmtInWords_zh_TW aiw = new AmtInWords_zh_TW();
        //	aiw.print (".23");	Error
        aiw.print("329,002,389.30");
    } //	main

} //	AmtInWords_zh_TW

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -