如何阻止 Kendo UI 网格列格式四舍五入
How to stop Kendo UI grid column format from rounding up
我有一个 Kendo UI 网格,在格式化列时将美分(可能还有美元)四舍五入,但不知道如何阻止它发生,只是说我有 123.456从数据库返回,当我将该列格式化为两位小数时,它会将美分金额四舍五入并返回为 123.46,如果格式为小数点后三位则不会四舍五入。
简而言之,我需要将列的格式设置为小数点后两位,但我不知道如何将数字四舍五入
let ds = [{
id: 1,
name: "Jane",
Amount: 252.6563
}];
(function() {
LoadTopGrid();
})();
function LoadTopGrid() {
$('#grid').kendoGrid({
dataSource: {
data: ds,
schema: {
model: {
id: "id",
fields: {
id: {
editable: false,
type: "number"
},
name: {
type: "string"
},
Amount: {
type: "number"
}
}
}
}
},
columns: [{
field: "id",
title: "ID",
width: "50px"
},
{
field: "name",
title: "First",
width: "150px"
},
{
field: "Amount",
title: "Amount",
width: "150px",
format: "{0:n2}"
}
],
selectable: "row",
change: function(e) {
console.log("I changed!");
},
height: 300
});
}
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.mobile.all.min.css">
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/angular.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/jszip.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/kendo.all.min.js"></script>
</head>
<div id="grid"></div>
我有一个 Kendo UI 网格,在格式化列时将美分(可能还有美元)四舍五入,但不知道如何阻止它发生,只是说我有 123.456从数据库返回,当我将该列格式化为两位小数时,它会将美分金额四舍五入并返回为 123.46,如果格式为小数点后三位则不会四舍五入。
简而言之,我需要将列的格式设置为小数点后两位,但我不知道如何将数字四舍五入
let ds = [{
id: 1,
name: "Jane",
Amount: 252.6563
}];
(function() {
LoadTopGrid();
})();
function LoadTopGrid() {
$('#grid').kendoGrid({
dataSource: {
data: ds,
schema: {
model: {
id: "id",
fields: {
id: {
editable: false,
type: "number"
},
name: {
type: "string"
},
Amount: {
type: "number"
}
}
}
}
},
columns: [{
field: "id",
title: "ID",
width: "50px"
},
{
field: "name",
title: "First",
width: "150px"
},
{
field: "Amount",
title: "Amount",
width: "150px",
format: "{0:n2}"
}
],
selectable: "row",
change: function(e) {
console.log("I changed!");
},
height: 300
});
}
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.3.1023/styles/kendo.mobile.all.min.css">
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/angular.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/jszip.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/kendo.all.min.js"></script>
</head>
<div id="grid"></div>