Kendo grid 格式数字以空格作为千​​位分隔符和两位小数

Kendo grid Format number with whitespace as thousand separator and two decimal places

我需要将列中的数字格式化为白色 space 作为千位分隔符并保留两位小数。例如:125895456.8942 -> 125 895 456.89

 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,
             },
          ]

我可以实现什么 w/o 文化?我有一个适用于千位分隔符但不适用于我的小数点后两位的函数

function numberWithSpaces(x) {
            return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
        }

这个怎么样:

function numberWithSpaces(x) {
        return kendo.toString(x, "##,#.##").replace(/,/g, " ")
}

您使用您的文化中常用的小数点分隔符(在本例中为“,”代表 en-US)格式化您的字符串,然后使用正则表达式将其替换为空格。 对于“12345678.0394”,您将得到“12 345 678.04”

您也可以将其内联到您的模板中:

template: '#= kendo.toString(sumStartDebit, "##,#.##").replace(/,/g, " ")#'