fnFormatNumber bug?

fnFormatNumber bug?

flarpyflarpy Posts: 47Questions: 0Answers: 0
edited April 2013 in General
Hi Allan

$('#cosTotal').html(settings.fnFormatNumber(cosTotal.toFixed(2)));
produces
1,240,964,.64
where I would expect
1,240,964.64

is the trailing comma before the decimal separator removable by config or is it a bug?

Thanks

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    fnFormatNumber is designed only to work with integers since it is specifically designed for displaying the paging information in DataTables which fundamentally has to be an integer! So there was no need to cope with floating point numbers.

    I'd suggest not using fnFormatNumber if you want to work with formatted numbers outside of the core DataTables functions, since it is effectively an internal function.

    It would be possible to alter the default function to suit your needs ( https://github.com/DataTables/DataTables/blob/master/media/src/model/model.defaults.js#L928 ), but you might want to consider using a number formatting library that is specifically designed or just a simple function. There is an example here: http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript/149099#149099 .

    Allan
  • flarpyflarpy Posts: 47Questions: 0Answers: 0
    Okay thanks, makes sense
This discussion has been closed.