Use browser's locale for currency format
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import { helper } from '@ember/component/helper';
|
import { helper } from '@ember/component/helper';
|
||||||
|
|
||||||
export default helper(function fmtFiatCurrency(params) {
|
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',
|
style: 'currency',
|
||||||
currency: params[1] || 'EUR',
|
currency: params[1] || 'EUR',
|
||||||
minimumFractionDigits: 2
|
currencyDisplay: 'code'
|
||||||
})
|
})
|
||||||
return formatter.format(params[0]);
|
return formatter.format(params[0]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ module('Integration | Helper | fmt-fiat-currency', function(hooks) {
|
|||||||
this.set('amount', 13.9);
|
this.set('amount', 13.9);
|
||||||
|
|
||||||
await render(hbs`{{fmt-fiat-currency this.amount}}`);
|
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'}}`);
|
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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user