java金额比较大小写_Java金额大小写的转换方法

更新时间:2023-07-26 19:38:49 阅读: 评论:0

java⾦额⽐较⼤⼩写_Java⾦额⼤⼩写的转换⽅法本⽂实例为⼤家分享了java⾦额⼤⼩写转换的具体代码,供⼤家参考,具体内容如下
/**
* @classname: numberconvert
* @description: todo
* @date 2013-3-07 下午16:08:10
* @version v1.0
*/
public class moneyutil {
/** ⼤写数字 */
private static final string[] numbers = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
/** 整数部分的单位 */
private static final string[] iunit = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万", "拾", "佰",
"仟" };
/** ⼩数部分的单位 */
private static final string[] dunit = { "⾓", "分", "厘" };
/**
* 得到⼤写⾦额。
*/
public static string tochine(string str) {
str = placeall(",", "");// 去掉","
string integerstr;// 整数部分数字
string decimalstr;// ⼩数部分数字
// 初始化:分离整数部分和⼩数部分
if (str.indexof(".") > 0) {
integerstr = str.substring(0, str.indexof("."));
decimalstr = str.substring(str.indexof(".") + 1);
} el if (str.indexof(".") == 0) {
integerstr = "";
decimalstr = str.substring(1);
} el {
integerstr = str;
decimalstr = "";
}
/
/ integerstr去掉⾸0,不必去掉decimalstr的尾0(超出部分舍去)
if (!integerstr.equals("")) {
integerstr = string(long.parlong(integerstr));
if (integerstr.equals("0")) {
integerstr = "";
}
}
// overflow超出处理能⼒,直接返回
if (integerstr.length() > iunit.length) {
system.out.println(str + ":超出处理能⼒");
return str;
}
int[] integers = toarray(integerstr);// 整数部分数字
boolean ismust5 = ismust5(integerstr);// 设置万单位
int[] decimals = toarray(decimalstr);// ⼩数部分数字
return getchineinteger(integers, ismust5) + getchinedecimal(decimals); }
/**
* 整数部分和⼩数部分转换为数组,从⾼位⾄低位
*/
private static int[] toarray(string number) {氛围的近义词
int[] array = new int[number.length()];
for (int i = 0; i < number.length(); i++) {
array[i] = integer.parint(number.substring(i, i + 1));
}
return array;
}
/**
* 得到中⽂⾦额的整数部分。
*/
private static string getchineinteger(int[] integers, boolean ismust5) { stringbuffer chineinteger = new stringbuffer("");
int length = integers.length;
for (int i = 0; i < length; i++) {
// 0出现在关键位置:1234(万)5678(亿)9012(万)3456(元)
// 特殊情况:10(拾元、壹拾元、壹拾万元、拾万元)
string key = "";
if (integers[i] == 0) {
if ((length - i) == 13)// 万(亿)(必填)
key = iunit[4];
el if ((length - i) == 9)// 亿(必填)
key = iunit[8];太原雪斋
吕代豪el if ((length - i) == 5 && ismust5)// 万(不必填)
key = iunit[4];
el if ((length - i) == 1)// 元(必填)
key = iunit[0];
/
/ 0遇⾮0时补零,不包含最后⼀位
if ((length - i) > 1 && integers[i + 1] != 0)
客户服务体系key += numbers[0];
}默默的爱着你
chineinteger.append(integers[i] == 0 ? key : (numbers[integers[i]] + iunit[length - i - 1])); }
string();
}
/**
* 得到中⽂⾦额的⼩数部分。
*/
private static string getchinedecimal(int[] decimals) {
stringbuffer chinedecimal = new stringbuffer("");
for (int i = 0; i < decimals.length; i++) {
// 舍去3位⼩数之后的
if (i == 3)
break;
chinedecimal.append(decimals[i] == 0 ? "" : (numbers[decimals[i]] + dunit[i]));
}
string();
}
/**
* 判断第5位数字的单位"万"是否应加。
*/
private static boolean ismust5(string integerstr) {
int length = integerstr.length();
if (length > 4) {
string subinteger = "";
if (length > 8) {
// 取得从低位数,第5到第8位的字串
subinteger = integerstr.substring(length - 8, length - 4);
} el {
subinteger = integerstr.substring(0, length - 4);
}
return integer.parint(subinteger) > 0;
} el {
return fal;
}
}
public static void main(string[] args) {
string number = "1.23";峨的组词
system.out.println(number + " " + hine(number));
number = "1234567890123456.123";
system.out.println(number + " " + hine(number));
詈词number = "0.0798";
system.out.println(number + " " + hine(number));
number = "10,001,000.09";
system.out.println(number + " " + hine(number));
number = "01.107700";
system.out.println(number + " " + hine(number));
}
}
伽利略怎么死的运⾏结果为:
1.23 壹元贰⾓叁分
1234567890123456.123 壹仟贰佰叁拾肆万伍仟陆佰柒拾捌亿玖仟零壹拾贰万叁仟肆佰伍拾陆元壹⾓贰分叁厘0.0798 柒分玖厘

本文发布于:2023-07-26 19:38:49,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1097765.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:部分   整数   转换   数字   单位
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图