Asp.net mvc 剑道网格格式数字,空格为千位分隔符,小数点后两位
我需要在一列中设置数字格式,其中空格为千位分隔符,小数点后两位。例如:125895456.8942->125895456.89Asp.net mvc 剑道网格格式数字,空格为千位分隔符,小数点后两位,asp.net-mvc,kendo-grid,kendo-asp.net-mvc,Asp.net Mvc,Kendo Grid,Kendo Asp.net Mvc,我需要在一列中设置数字格式,其中空格为千位分隔符,小数点后两位。例如:125895456.8942->125895456.89 columns: [ { field: "sumStartDebit", title: "Debit", width: "130px", template: function (dataItem) { if (dataItem.s
columns: [
{
field: "sumStartDebit",
title: "Debit",
width: "130px",
template: function (dataItem) {
if (dataItem.sumStartDebit == 0) { return "" }
else if (dataItem.sumStartDebit < 0) { return "<span style='color:red'>" + dataItem.sumStartDebit + "</span>" }
else { return "<span>" + dataItem.sumStartDebit + "</span>" }
},
locked: true,
},
]
那么这个呢:
function numberWithSpaces(x) {
return kendo.toString(x, "##,#.##").replace(/,/g, " ")
}
您可以使用区域性中常用的十进制分隔符格式化字符串(在本例中为“,”表示en-US),然后使用正则表达式将其替换为空白。
对于“12345678.0394”,您将得到“12345678.04”
您也可以在模板中内嵌此内容:
template: '#= kendo.toString(sumStartDebit, "##,#.##").replace(/,/g, " ")#'
您是否正在寻找一个函数以您想要的方式分割每个数字?您好,是的。我认为函数是个好主意。我已经更新了我的问题,以显示我使用了什么函数。每个数字都像你的例子一样出现了吗?那么它就像340934209.0025?所以总是有4个小数位。幸运的是,数字可以有2到3个小数位
template: '#= kendo.toString(sumStartDebit, "##,#.##").replace(/,/g, " ")#'