1

How to prevent this value from rounding and 2 decimal point only? I tried this but is not working,

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [ {
    field: "colTwo",
    format: "{0:n2}",
    editor: amountE
  } ],
  filterable: true,
  dataSource: [ { colTwo: 0.377941} ]
});

function amountE(container, options) {
  $('<input name="' + options.field + '"/>')
    .appendTo(container)
    .kendoNumericTextBox({
    decimal: 1,
    round: false,
    //format: "{0:n2}",
  })
}
i.signori
  • 585
  • 3
  • 16

1 Answers1

2

How to prevent this value from rounding?

Try This

By entering the format "{0: n2}", inside the table, you're asking to round to two decimal places. Change the format to get the original value or different rounds.

$("#grid").kendoGrid({
  columns: [ {
    field: "colTwo",
    format: "{0}"
  } ],
  filterable: true,
  dataSource: [ { colTwo: 0.377941} ]
});
<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/datepicker/index">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.default.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
</head>
<body>
  
<div id="grid"></div>
</body>
</html>

And it is possible to display only 2 decimal point?

In this case, I recommend using templates by truncating the value. At this link you can find examples of how to truncate a value on javascript (without rounding). In this instead how to do it without using the Math library.

$("#grid").kendoGrid({
  columns: [ {
    field: "colTwo",
    format: "{0}",
    template: '#= (((colTwo * 100)|0)/100) #'

  } ],
  filterable: true,
  dataSource: [ { colTwo: 0.377941} ]
});
<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/datepicker/index">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.default.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
</head>
<body>
  
<div id="grid"></div>
</body>
</html>

Dojo here.

i.signori
  • 585
  • 3
  • 16