悬浮展示中文金额效果
js代码(格式化的函数)
function formatNumber(num) {
if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)) {
return num;
}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp("(\\d)(\\d{3})(,|$)");
while (re.test(b)) b = b.replace(re, "$1,$2$3");
var value = addChineseUnit(num, 5);
var content = '';
if (value != undefined) {
//style="text-decoration: none"属性让超链接a下面不再显示下划线
content = '<div href="#" title="' + value + '" class="easyui-tooltip easyui-linkbutton" style="text-decoration: none">' + (a + "" + b + "" + c) + '</div>';
}
return content;
}
/*添加中文金额显示*/
function addChineseUnit(number, decimalDigit) {
var addWan = function (integer, number, mutiple, decimalDigit) {
var digit = getDigit(integer);
if (digit > 3) {
var remainder = digit % 8;
if (remainder >= 5) {
// ‘十万’、‘百万’、‘千万’显示为‘万’
remainder = 4;
}
return Math.round(number / Math.pow(10, remainder + mutiple - decimalDigit)) / Math.pow(10, decimalDigit) + '万';
} else {
return Math.round(number / Math.pow(10, mutiple - decimalDigit)) / Math.pow(10, decimalDigit);
}
};
var getDigit = function (integer) {
var digit = -1;
while (integer >= 1) {
digit++;
integer = integer / 10;
}
return digit;
};
return function (number, decimalDigit) {
decimalDigit = decimalDigit == null ? 2 : decimalDigit;
var integer = Math.floor(number);
var digit = getDigit(integer);
var unit = [];
if (digit > 3) {
var multiple = Math.floor(digit / 8);
if (multiple >= 1) {
var tmp = Math.round(integer / Math.pow(10, 8 * multiple));
unit.push(addWan(tmp, number, 8 * multiple, decimalDigit));
for (var i = 0; i < multiple; i++) {
unit.push('亿');
}
return unit.join('');
} else {
return addWan(integer, number, 0, decimalDigit);
}
} else {
return number;
}
}(number, decimalDigit);
}
easyui的表格field字段写法
{
field: 'budgetAvailableAmount',
op: 'sum',
title: "可用金额",
width: '15%',
formatter: function (value) {
return formatNumber(value);
}
}
文章评论