Skip to content

Instantly share code, notes, and snippets.

@moklick
Created August 17, 2018 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moklick/da8341ab4ad999c169e05173890d1712 to your computer and use it in GitHub Desktop.
Save moklick/da8341ab4ad999c169e05173890d1712 to your computer and use it in GitHub Desktop.
import { formatDefaultLocale } from 'd3-format';
const germanNumberFormat = formatDefaultLocale({
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['€', '']
});
export function numberFormat(num, decimals = 0) {
if (typeof num === 'undefined') {
return '';
}
return germanNumberFormat.format(`,.${decimals}f`)(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment