JAVA编写 将阿拉伯数字转换成中文大写(不要Script的)
来源:百度知道 编辑:UC知道 时间:2024/06/05 18:28:09
public class MoneyUtil {
public static String[] chineseDigits = new String[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
/**
* 把金额转换为汉字表示的数量,小数点后四舍五入保留两位
* @param amount
* @return
*/
public static String amountToChinese(double amount) {
if(amount > 99999999999999.99 || amount < -99999999999999.99)
throw new IllegalArgumentException("参数值超出允许范围 (-99999999999999.99 ~ 99999999999999.99)!");
boolean negative = false;
if(amount < 0) {
negative = true;
amount = amount * (-1);
}
long temp = Math.round(amount * 100);
int numFen = (int)(temp % 10); // 分
temp = temp / 10;
int numJiao = (int)(temp % 10); //角