Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display only 3 digits after decimal in DataTables

I am trying to display only 3 digits after decimal point but I'm unable to do so. I tried with toFixed() method but I couldn't succeed.

Here's my fiddle.

HTML source code:

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>DATE</th>
            <th>CODE</th>
            <th>PRODUCT</th>
            <th>QUANTITY</th>
            <th>UNIT</th>
            <th>VALUE</th>
            <th>COUNTRY</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>01/01/2017</td>
            <td>84571001</td>
            <td>MACHININGCENTRESHORIZONTAL</td>
            <td>13</td>
            <td>NOS</td>
            <td>22.1382568</td>
            <td>JAPAN</td>
        </tr>
        <tr>
            <td>03/01/2017</td>
            <td>84571001</td>
            <td>MACHININGCENTRESHORIZONTAL</td>
            <td>33</td>
            <td>NOS</td>
            <td>54.5104524</td>
            <td>JAPAN</td>
        </tr>
    </tbody>
</table>

Can anyone help me out?

like image 297
Manoj Kadolkar Avatar asked Dec 03 '25 09:12

Manoj Kadolkar


1 Answers

The easiest is to use the built-in number helper :

columnDefs: [{
  targets: [5],
  render: $.fn.dataTable.render.number(',', '.', 3)
}]

Updated fiddle -> http://jsfiddle.net/ebRXw/3627/ Just an example, follow the link for details about all the options you can use along with the number renderer.

like image 94
davidkonrad Avatar answered Dec 04 '25 23:12

davidkonrad