• Resolved bwolfe07

    (@bwolfe07)


    Hello,

    Pretty simple question but I have not been able to get the answer to. How can I drop zeros from numbers such as 2,857.50 to 2,857.5

    I have been using the formula:
    “columnDefs”: [ { “orderSequence”: [ “desc”, “asc” ], “targets”: [ 1, 2, 3, 4 ] } ]

    however this will not insert commas: 2857.5

    I’ll then try this:
    “columnDefs”: [ { “targets”: [ 1, 2, 3, 4 ], “render”: $.fn.dataTable.render.number( ‘,’, ‘.’, 2, ” ) } ]

    This will keep the comma but not drop off the zero: 2,857.50

    Any help to combine those 2 things, have commas and also drop zeros would be much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    If at all, your second piece of code could work. However, I’m not really familiar with theses commands, as they are code for the DataTables JS library. You might therefore want to check what the individual parameters in that $.fn.dataTable.render.number() function call stand for.

    Regards,
    Tobias

    Thread Starter bwolfe07

    (@bwolfe07)

    Hello Tobias,

    Thank you for the quick reply. I am not sure where I got the second code from, however the main goal is to have 3 things…

    insert commas at the thousands
    drop insignificant zeros
    when sorting a column it will display the largest number first

    if you have a snippet of code that can accomplish this I will replace what I currently have.

    Thank you!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    the best place to start looking would then probably be the DataTables documentation at https://datatables.net/reference/option/columns.render
    The “Examples” section has some ideas that might get you started on changing each number to the desired format.

    Regards,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Drop zeros from tables’ is closed to new replies.