Bug on formatters $.fn.dataTable.render.number (DataTables 1.10.12)

Bug on formatters $.fn.dataTable.render.number (DataTables 1.10.12)

caste1969caste1969 Posts: 2Questions: 1Answers: 0
edited July 2016 in Free community support

I think there is perhaps, a problem on $.fn.dataTable.render.number.
I use render: $.fn.dataTable.render.number('.', ',', 2,'€ ') on column for render euro values
For the number 0.999860600 it will return 0,00 €. That's impossible
It's a bug or other problem. Many thanks

Answers

  • caste1969caste1969 Posts: 2Questions: 1Answers: 0

    After debug render function in jquery.datatables.js. I found this piece of code that is probably not correct.
    d is number like 0.999860600, precision =2
    -- var intPart = parseInt( d, 10 );
    intPart is 0.
    -- var floatPart = precision ? decimal+(d - intPart).toFixed( precision ).substring( 2 ):'';
    that's wrong: 0.999860600.toFixed =1.00 and decimal is floatPart is ,00
    so final number=0,00
    I think it is wrong to use toFixed because it make a round of decimal part number, with the result of visualize an incorrect value.

  • allanallan Posts: 64,958Questions: 1Answers: 10,759 Site admin

    Thank you for pointing this out! It looks like there might be a DataTables 1.10.13 after all (rather than a major jump)!

    I'll post back when I've committed the fix.

    Allan

  • allanallan Posts: 64,958Questions: 1Answers: 10,759 Site admin

    After a bit of a delay (sorry), I've finally committed the fix for this and a bunch of unit tests to make sure it doesn't happen again.

    The nightly will rebuild shortly with this change if you would like to try it out, and it will also be available in the 1.10.13 release which I plan to make in the next week or so.

    Allan

This discussion has been closed.