function number2Chinese(n) { if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)) return '數據非法'; let unit = '京億萬仟佰拾兆萬仟佰拾億仟佰拾萬仟佰拾元角分', str = ''; n += '00'; let p = n.indexOf('.'); if (p >= 0) n = n.substring(0, p) + n.substr(p + 1, 2); unit = unit.substr(unit.length - n.length); for (let i = 0; i < n.length; i++) str += '零壹貳叄肆伍陸柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i); return str .replace(/零(仟|佰|拾|角)/g, '零') .replace(/(零)+/g, '零') .replace(/零(兆|萬|億|元)/g, '$1') .replace(/(兆|億)萬/g, '$1') .replace(/(京|兆)億/g, '$1') .replace(/(京)兆/g, '$1') .replace(/(京|兆|億|仟|佰|拾)(萬?)(.)仟/g, '$1$2零$3仟') .replace(/^元零?|零分/g, '') .replace(/(元|角)$/g, '$1整'); }