<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>大金额</title>
</head>
<body>
<script>
function daxie(n) {
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "数据非法";
var unit = "千百拾亿千百拾万千百拾元角分", str = "";
n += "00";
var p = n.indexOf('.');
if (p >= 0)
n = n.substring(0, p) + n.substr(p + 1, 2);
unit = unit.substr(unit.length - n.length);
for (var 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$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
}
var qipa_number = daxie(250);
alert('大写整数:' + qipa_number);
function bigNumberTransform(value) {
let param = {};
let k = 10000,
sizes = ['', '万', '亿', '万亿'],
i;
if (value < k) {
param.value = value.toFixed(2)
param.unit = ''
} else {
i = Math.floor(Math.log(value) / Math.log(k));
param.value = ((value / Math.pow(k, i))).toFixed(2);
param.unit = sizes[i];
}
let number = param.value + param.unit;
return number;
}
// 带上单位
var qipa_250 = bigNumberTransform(25020808345.564);
alert(qipa_250);
</script>
</body>
</html>