Commas for decimal place

Sort numbers correctly which use a comma as the decimal place.

  • Author: Allan Jardine
  • Deprecated: This plug-in has been deprecated and replaced with other functionality. Please see the detailed description below for more information.

It is not uncommon for non-English speaking countries to use a comma for a decimal place. This sorting plug-in shows how that can be taken account of in sorting by adding the type numeric-comma to DataTables. A type detection plug-in for this sorting method is provided below.

Please note that the 'Formatted numbers' type detection and sorting plug-ins offer greater flexibility that this plug-in and should be used in preference to this method.

Plug-in code

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "numeric-comma-pre": function ( a ) {
        var x = (a == "-") ? 0 : a.replace( /,/, "." );
        return parseFloat( x );

    "numeric-comma-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));

    "numeric-comma-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
} );


This plug-in is available on the DataTables CDN:


Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!


$('#example').dataTable( {
     columnDefs: [
       { type: 'numeric-comma', targets: 0 }
  } );