Use browser's locale for currency format

This commit is contained in:
2020-07-09 22:15:25 +02:00
parent 4849a755dc
commit a96cca879d
2 changed files with 9 additions and 4 deletions
+3 -2
View File
@@ -1,10 +1,11 @@
import { helper } from '@ember/component/helper';
export default helper(function fmtFiatCurrency(params) {
const formatter = new Intl.NumberFormat('en-US', {
const lang = navigator.language || navigator.userLanguage;
const formatter = new Intl.NumberFormat(lang, {
style: 'currency',
currency: params[1] || 'EUR',
minimumFractionDigits: 2
currencyDisplay: 'code'
})
return formatter.format(params[0]);
});
@@ -10,9 +10,13 @@ module('Integration | Helper | fmt-fiat-currency', function(hooks) {
this.set('amount', 13.9);
await render(hbs`{{fmt-fiat-currency this.amount}}`);
assert.equal(this.element.textContent.trim(), '€13.90', 'using EUR amount by default');
assert.ok(this.element.textContent.trim().match(/13.90/),
'formats the number with two decimals');
assert.ok(this.element.textContent.trim().match(/EUR/),
'using EUR by default');
await render(hbs`{{fmt-fiat-currency this.amount 'USD'}}`);
assert.equal(this.element.textContent.trim(), '$13.90', 'using the defined currency');
assert.ok(this.element.textContent.trim().match(/USD/),
'using defined currency when given');
});
});