function converToZH(numberVal){ var ZH_VAL = "零壹贰叁肆伍陆柒捌玖"; // 汉字数字 var UNIT = "万仟佰拾亿仟佰拾万仟佰拾元角分"; // 对应单位 var n_money = Number(numberVal); var negative = false; if(n_money == 0) return "零元整"; if(n_money < 0){ negative = true; n_money = -n_money; } var s_money = String(Math.round(n_money*100)); var len = s_money.length; var pos = 0; var result = ''; var zeroFlag = false; while(pos < len){ var num = s_money.charAt(len-pos-1); if(num == '0'){ //分位 if(pos == 0){ } //元、万、亿位 else if(pos == 2 || pos == 6 || pos == 10){ if(!zeroFlag) result = UNIT.charAt(UNIT.length-pos-1) + '零' + result; else result = UNIT.charAt(UNIT.length-pos-1) + result; } else if(!zeroFlag){ result = '零' + result; } zeroFlag = true; } else{ zeroFlag = false; result = ZH_VAL.charAt(num) + UNIT.charAt(UNIT.length-pos-1) + result; } pos++; } if(Number(s_money)%10 == 0 || Number(s_money)%100 == 0 ){ result = result + '整'; } return negative? '负' + result : result; }
详细解决方案
阿拉伯数字转金额汉语大写
热度:272 发布时间:2012-10-24 14:15:58.0
相关解决方案