金额小数转换成中文大写金额
来源:互联网 发布:mac版spss 如何安装 编辑:程序博客网 时间:2024/05/01 01:58
package com.itext.test;
/**
* 金额小数转换成中文大写金额
* @author Neil Han
*
*/
public class ConvertMoneyToUppercase {
private static final String UNIT[] = { "万", "千", "佰", "拾", "亿", "千", "佰",
"拾", "万", "千", "佰", "拾", "元", "角", "分" };
private static final String NUM[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆",
"柒", "捌", "玖" };
private static final double MAX_VALUE = 9999999999999.99D;
/**
* 将金额小数转换成中文大写金额
* @param money
* @return result
*/
public static String convertMoney(double money) {
if (money < 0 || money > MAX_VALUE)
return "参数非法!";
long money1 = Math.round(money * 100); // 四舍五入到分
if (money1 == 0)
return "零元整";
String strMoney = String.valueOf(money1);
int numIndex = 0; // numIndex用于选择金额数值
int unitIndex = UNIT.length - strMoney.length(); // unitIndex用于选择金额单位
boolean isZero = false; // 用于判断当前为是否为零
String result = "";
for (; numIndex < strMoney.length(); numIndex++, unitIndex++) {
char num = strMoney.charAt(numIndex);
if (num == '0') {
isZero = true;
if (UNIT[unitIndex] == "亿" || UNIT[unitIndex] == "万"
|| UNIT[unitIndex] == "元") { // 如果当前位是亿、万、元,且数值为零
result = result + UNIT[unitIndex]; //补单位亿、万、元
isZero = false;
}
}else {
if (isZero) {
result = result + "零";
isZero = false;
}
result = result + NUM[Integer.parseInt(String.valueOf(num))] + UNIT[unitIndex];
}
}
//不是角分结尾就加"整"字
if (!result.endsWith("角")&&!result.endsWith("分")) {
result = result + "整";
}
//例如没有这行代码,数值"400000001101.2",输出就是"肆千亿万壹千壹佰零壹元贰角"
result = result.replaceAll("亿万", "亿");
return result;
}
public static void main(String[] args) {
double value = Double.parseDouble("210");
System.out.println("您输入的金额(小写)为:" + value);
System.out.println("您输入的金额(大写)为:" + convertMoney(value));
}
}
/**
* 金额小数转换成中文大写金额
* @author Neil Han
*
*/
public class ConvertMoneyToUppercase {
private static final String UNIT[] = { "万", "千", "佰", "拾", "亿", "千", "佰",
"拾", "万", "千", "佰", "拾", "元", "角", "分" };
private static final String NUM[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆",
"柒", "捌", "玖" };
private static final double MAX_VALUE = 9999999999999.99D;
/**
* 将金额小数转换成中文大写金额
* @param money
* @return result
*/
public static String convertMoney(double money) {
if (money < 0 || money > MAX_VALUE)
return "参数非法!";
long money1 = Math.round(money * 100); // 四舍五入到分
if (money1 == 0)
return "零元整";
String strMoney = String.valueOf(money1);
int numIndex = 0; // numIndex用于选择金额数值
int unitIndex = UNIT.length - strMoney.length(); // unitIndex用于选择金额单位
boolean isZero = false; // 用于判断当前为是否为零
String result = "";
for (; numIndex < strMoney.length(); numIndex++, unitIndex++) {
char num = strMoney.charAt(numIndex);
if (num == '0') {
isZero = true;
if (UNIT[unitIndex] == "亿" || UNIT[unitIndex] == "万"
|| UNIT[unitIndex] == "元") { // 如果当前位是亿、万、元,且数值为零
result = result + UNIT[unitIndex]; //补单位亿、万、元
isZero = false;
}
}else {
if (isZero) {
result = result + "零";
isZero = false;
}
result = result + NUM[Integer.parseInt(String.valueOf(num))] + UNIT[unitIndex];
}
}
//不是角分结尾就加"整"字
if (!result.endsWith("角")&&!result.endsWith("分")) {
result = result + "整";
}
//例如没有这行代码,数值"400000001101.2",输出就是"肆千亿万壹千壹佰零壹元贰角"
result = result.replaceAll("亿万", "亿");
return result;
}
public static void main(String[] args) {
double value = Double.parseDouble("210");
System.out.println("您输入的金额(小写)为:" + value);
System.out.println("您输入的金额(大写)为:" + convertMoney(value));
}
}
0 0
- 金额小数转换成中文大写金额
- 小写金额转换成中文大写金额
- 小写金额转换成中文大写金额
- 金额转换成中文大写
- 阿拉伯数字转换成金额大写金额(包括小数)
- 中文大写金额转换
- 将小写的金额转换成中文的大写金额
- 使用 JAVA 将数字金额转换成大写中文金额
- 将小写金额转换成中文大写金额的方法
- PHP 数字金额转换成中文大写金额的函数
- 阿拉伯数字转换成中文大写金额
- 讲金额(数字)转换成中文大写
- 金额转换成大写
- 金额转换成大写
- 金额转换成大写
- Java中文大写金额转换
- 金额转换为中文大写
- 金额转换为中文大写
- 关于s7 300的中值滤波
- ZooKeeper之(五)集群管理
- baso
- Spring MVC 教程,快速入门,深入分析
- 16.10.27
- 金额小数转换成中文大写金额
- 学生信息管理
- 虚函数、消息传递、this指针、构造函数、模板类3个
- 快速定位解决Android内存泄漏
- SuperPlayer 是一个基于 IjkPlayer 的控制器,支持手势操作,滑动快进,快退,支持,上滑音量亮度的变化,支持指点位置播放,播放源的切换
- java--swing--鼠标小手样式
- Linux命令之"at"
- 带参数的main函数和命令行参数
- navigation stack 中amcl 源码解读