ChinaNumber = (numberValue) => {
numberValue = Number(numberValue)+''
var unit = "十百千万十百千"; // 对应单位
var chineseNumber = "零一二三四五六七八九"; // 汉字数字
if(numberValue.indexOf('.') < 0){
return "百分之"+chineseNumber[numberValue];
}
//获取小数点后位数
var pointNumber = numberValue.split(".")[1].length;
//得到中文单位
var unitStr = unit.substring(pointNumber , pointNumber + 1);
//大于5位后面加上万,目前只支持到千万,后需要支持更多需加逻辑判断
if (pointNumber >= 5) {
unitStr = unitStr + '万';
}
//得到中文值(只支持到万位的数字,超过则显示异常)
var number = Math.pow(10, pointNumber);
var rateNumber = numberValue * number /10;
var rateLenth = rateNumber.toString().length;
var rateStr = '';
//拼接中文值
for (var index = 0; index < rateLenth; index++) {
var strIndex = rateNumber.toString().substring(index, index + 1)
if(strIndex == "."){
rateStr = rateStr + '点'
}else{
rateStr = rateStr + chineseNumber.substring(Number(strIndex),Number(strIndex) + 1);
}
}
//拼接中文结果
var chineseValue = unitStr + '分之' + rateStr; // 转换后的汉字金额
return chineseValue;
}
ChinaNumber = (numberValue) => {
numberValue = Number(numberValue)+''
if(numberValue.indexOf('.') < 0){
return numberValue;
}
var unit = "十百千万十百千"; // 对应单位
var chineseNumber = "零一二三四五六七八九"; // 汉字数字
//获取小数点后位数
var pointNumber
for (var i = 0 ;i<numberValue.split(".")[1].length; i++){
if(numberValue.split(".")[1][i]>0){
pointNumber = i+1
break
}
}
//得到中文单位
var unitStr = unit.substring(pointNumber - 1, pointNumber);
//大于5位后面加上万,目前只支持到千万,后需要支持更多需加逻辑判断
if (pointNumber >= 5) {
unitStr = unitStr + '万';
}
//得到中文值(只支持到万位的数字,超过则显示异常)
var number = Math.pow(10, pointNumber+1);
var rateNumber = Number(numberValue) * number /10;
var rateLenth = rateNumber.toString().length;
var rateStr = '';
//拼接中文值
for (var index = 0; index < rateLenth; index++) {
var strIndex = rateNumber.toString().substring(index, index + 1)
if(strIndex == "."){
rateStr = rateStr + '点'
}else{
rateStr = rateStr + chineseNumber.substring(Number(strIndex),Number(strIndex) + 1);
}
}
//拼接中文结果
var chineseValue = unitStr + '分之' + rateStr; // 转换后的汉字金额
return chineseValue;
}