开发时用到的, 在网上找的 ,后来自己改了改.试用我们项目的. 实现了 15 转为 十五 , 123 转为一百二十三 ......
js代码分享
function convertToChinese(num) {
if (!/^\d*(\.\d*)?$/.test(num)) { alert("Number is wrong!"); return "Number is wrong!"; }
var AA = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
var BB = new Array("", "十", "百", "千", "万", "亿", "点", "");
var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
for (var i = a[0].length - 1; i >= 0; i--) {
switch (k) {
case 0: re = BB[7] + re; break;
case 4: if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
if (!/^\d*(\.\d*)?$/.test(num)) { alert("Number is wrong!"); return "Number is wrong!"; }
var AA = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
var BB = new Array("", "十", "百", "千", "万", "亿", "点", "");
var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
for (var i = a[0].length - 1; i >= 0; i--) {
switch (k) {
case 0: re = BB[7] + re; break;
case 4: if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))