{hero}

formatNumber

Since: DataTables 1.10

Number formatting callback function.

Description

DataTables will display numbers in a few different locations when drawing information about a table, for example in the table's information element and the pagination controls. When working with large numbers it is often useful to format it for readability by separating the thousand units - for example 1 million is rendered as "1,000,000", allowing the user to see at a glance what order of magnitude the number shows.

This function allows complete control over how that formatting is performed. By default DataTables will use the character specified in language.thousands (in turn, that, by default, is a comma) as the thousands separator.

Type

function formatNumber( toFormat )

Parameters:
Returns:

Formatted string for DataTables to show the number

Default

Shows numbers grouped as thousands with a comma separator

Example

Show large numbers with a ' separator:

new DataTable('#myTable', {
	formatNumber: function (toFormat) {
		return toFormat.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "'");
	}
});

Related

The following options are directly related and may also be useful in your application development.