Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to format amounts to a specific currency? #181

Closed
fstaoe opened this issue Jun 19, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@fstaoe
Copy link

commented Jun 19, 2019

I am working with amounts in Euro and I would like to show the amount formatted to Euro (€) independently from the selected locale. Is there any way to do so?

@issue-label-bot issue-label-bot bot added the #question label Jun 19, 2019

@issue-label-bot

This comment has been minimized.

Copy link

commented Jun 19, 2019

Issue-Label Bot is automatically applying the label #question to this issue, with a confidence of 0.95. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@kristw

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

You may have to resort to d3-format at the moment.

import { formatLocale } from 'd3-format';

const locale = formatLocale({
  "decimal": ".",
  "thousands": ",",
  "grouping": [3],
  "currency": ["", ""],
});

const formatEuro = locale.format('$,.2f'); // Use $ as placeholder for currency (€).
formatEuro(value); // '€200.00'
@fstaoe

This comment has been minimized.

Copy link
Author

commented Jun 19, 2019

@kristw Thank you for reply.

Which would be the way to pass that definition and integrate it with the current number format implementation in Superset?

Question about @superset-ui: Is there any plan to have it configurable, in order to pass that definition to the component?

Thank you in advance.

@kristw

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

import { formatLocale } from 'd3-format';
import { getNumberFormatterRegistry, NumberFormatter } from '@superset-ui/number-format';

const locale = formatLocale({
  "decimal": ".",
  "thousands": ",",
  "grouping": [3],
  "currency": ["", ""],
});

const formatEuro = locale.format('$,.2f'); // Use $ as placeholder for currency (€).
formatEuro(value); // '€200.00'

getNumberFormatterRegistry().registerValue('EURO', new NumberFormatter({
  id: 'EURO',
  formatFunc: value => formatEuro(value)
}));

// then you can refer to 'EURO' in place of format string in your Superset charts.
@fstaoe

This comment has been minimized.

Copy link
Author

commented Jun 19, 2019

@kristw Thank you so much.

@kristw kristw closed this in #182 Jun 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.