Flask接口签名sign原理与实例代码浅析
382
2023-01-08
java实现阿拉伯数字转汉字数字
本文实例为大家分享了java实现阿拉伯数字转汉字数字的具体代码,供大家参考,具体内容如下
package bin;
/**
* @author Elsa
* @param args
* @param 2013-1-21
*/
public class DoubleTest {
static String[] units = { "", "十", "百", "千", "万", "十万", "百万", "千万", "亿",
"十亿", "百亿", "千亿", "万亿" };
static char[] numArray = { '零', '一', '二', '三', '四', '五', '六', '七', '八', '九' };
/**
* 测试
* @param args
*/
public static void main(String[] args) {
RtyEWint num = 234234324;
String numStr = foematInteger(num);
System.out.println("num= " + num + ", convert result: " + numStr);
double decimal = 12312;
System.out
.println("============================================================");
String decStr = formatDecimal(decimal);
System.out.println("decimal= " + decimal + ", decStr: " + decStr);
}
private static String foematInteger(int num) {
char[] val = String.valueOf(num).toCharArray();
int len = val.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
String m = val[i] + "";
int n = Integer.valueOf(m);
boolean isZero = n == 0;
String unit = units[(len - 1) - i];
if (isZero) {
if ('0' == val[i - 1]) {
continue;
} else {
sb.append(numArray[n]);
}
} else {
sb.append(numArray[n]);
sb.append(unit);
}
}
return sb.toString();
}
/**
* 对于double类型的的装换
*
* @param decimal
* @return
*/
private static String formatDecimal(double decimal) {
String decimals = String.valueOf(decimal);
int decIndex = decimals.indexOf(".");
int integ = Integer.valueOf(decimals.substring(0, decIndex));
int dec = Integer.valueOf(decimals.substring(decIndex + 1));
String result = foematInteger(integ) http://+ "." + formatFractionalPart(dec);
return result;
}
/**
* 对整数类型的转换
*
* @param decimal
* @return
*/
private static String formatFractionalPart(int decimal) {
char[] val = String.valueOf(decimal).toCharArray();
int len = val.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
int n = Integer.valueOf(val[i] + "");
sb.append(numArray[n]);
}
return sb.toString();
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~