-
java实现小写金额转换大写金额
- package com.sunboon.jiexi;
-
-
-
-
-
-
- public class MoneyUtil {
-
- private static final String[] NUMBERS = { "零", "壹", "贰", "叁", "肆", "伍",
- "陆", "柒", "捌", "玖" };
-
-
- private static final String[] IUNIT = { "元", "拾", "佰", "仟", "万", "拾", "佰",
- "仟", "亿", "拾", "佰", "仟", "万", "拾", "佰", "仟" };
-
-
- private static final String[] DUNIT = { "角", "分", "厘" };
-
-
-
-
- public static String toChinese(String str) {
- str = str.replaceAll(",", "");
- String integerStr;
- String decimalStr;
-
- if (str.indexOf(".") > 0) {
- integerStr = str.substring(0, str.indexOf("."));
- decimalStr = str.substring(str.indexOf(".") + 1);
- } else if (str.indexOf(".") == 0) {
- integerStr = "";
- decimalStr = str.substring(1);
- } else {
- integerStr = str;
- decimalStr = "";
- }
-
- if (!integerStr.equals("")) {
- integerStr = Long.toString(Long.parseLong(integerStr));
- if (integerStr.equals("0")) {
- integerStr = "";
- }
- }
-
- if (integerStr.length() > IUNIT.length) {
- System.out.println(str + ":超出处理能力");
- return str;
- }
-
- int[] integers = toArray(integerStr);
- boolean isMust5 = isMust5(integerStr);
- int[] decimals = toArray(decimalStr);
- return getChineseInteger(integers, isMust5)
- + getChineseDecimal(decimals);
- }
-
-
-
-
- private static int[] toArray(String number) {
- int[] array = new int[number.length()];
- for (int i = 0; i < number.length(); i++) {
- array[i] = Integer.parseInt(number.substring(i, i + 1));
- }
- return array;
- }
-
-
-
- 将夜www.jiangyea.com
- private static String getChineseInteger(int[] integers, boolean isMust5) {
- StringBuffer chineseInteger = new StringBuffer("");
- int length = integers.length;
- for (int i = 0; i < length; i++) {
-
-
- String key = "";
- if (integers[i] == 0) {
- if ((length - i) == 13)
- key = IUNIT[4];
- else if ((length - i) == 9)
- key = IUNIT[8];
- else if ((length - i) == 5 && isMust5)
- key = IUNIT[4];
- else if ((length - i) == 1)
- key = IUNIT[0];
-
- if ((length - i) > 1 && integers[i + 1] != 0)
- key += NUMBERS[0];
- }
- chineseInteger.append(integers[i] == 0 ? key
- : (NUMBERS[integers[i]] + IUNIT[length - i - 1]));
- }
- return chineseInteger.toString();
- }
-
-
-
-
- private static String getChineseDecimal(int[] decimals) {
- StringBuffer chineseDecimal = new StringBuffer("");
- for (int i = 0; i < decimals.length; i++) {
-
- if (i == 3)
- break;
- chineseDecimal.append(decimals[i] == 0 ? ""
- : (NUMBERS[decimals[i]] + DUNIT[i]));
- }
- return chineseDecimal.toString();
- }
-
-
-
-
- private static boolean isMust5(String integerStr) {
- int length = integerStr.length();
- if (length > 4) {
- String subInteger = "";
- if (length > 8) {
-
- subInteger = integerStr.substring(length - 8, length - 4);
- } else {
- subInteger = integerStr.substring(0, length - 4);
- }
- return Integer.parseInt(subInteger) > 0;
- } else {
- return false;
- }
- }
-
- public static void main(String[] args) {
- MoneyUtil moneyUtil = new MoneyUtil();
- System.out.println(moneyUtil.toChinese("5000.23"));
- }
-
- }
-
相关阅读:
在windows下安装mysql2 的问题解决 兰猫
物料在XXX仓库不存在
sapcar解压缩
采购信息源(采购信息记录、合同、计划协议、报价)
拓端tecdat|R语言矩阵特征值分解(谱分解)和奇异值分解(SVD)特征向量分析有价证券数据
拓端tecdat|Python面板时间序列数据预测:格兰杰因果关系检验Granger causality test药品销售实例与可视化
拓端tecdat|R语言分布滞后线性和非线性模型(DLNM)分析空气污染(臭氧)、温度对死亡率时间序列数据的影响
拓端tecdat|Python在线零售数据关联规则挖掘Apriori算法数据可视化
拓端tecdat|R语言ARIMAGARCH波动率模型预测股票市场苹果公司日收益率时间序列
Google编码规范
-
原文地址:https://www.cnblogs.com/jiangye/p/3344014.html
Copyright © 2020-2023
润新知