Skip to content

Commit

Permalink
fix(dinero#toFormat): Use toRoundedUnit instead of toRounded in toFor…
Browse files Browse the repository at this point in the history
…mat method to get rounded value
  • Loading branch information
sarahdayan committed Mar 13, 2018
1 parent 13ba7ba commit 9b2990d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dinero.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ const Dinero = options => {
toFormat(format) {
const formatter = Format(format || globalFormat)

return this.toUnit().toLocaleString(this.getLocale(), {
return this.toRoundedUnit(
formatter.getMinimumFractionDigits()
).toLocaleString(this.getLocale(), {
currencyDisplay: formatter.getCurrencyDisplay(),
useGrouping: formatter.getUseGrouping(),
minimumFractionDigits: formatter.getMinimumFractionDigits(),
Expand Down
5 changes: 5 additions & 0 deletions test/unit/dinero.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ describe('Dinero', () => {
Dinero({ amount: 200000, currency: 'EUR' }).toFormat('0.0')
).to.equal('2000.0')
})
it('should return the properly formatted amount (one fraction digit, rounded)', () => {
expect(
Dinero({ amount: 1155, currency: 'EUR' }).toFormat('0.0')
).to.equal('11.6')
})
it('should return the properly formatted amount (use grouping)', () => {
expect(
Dinero({ amount: 200000, currency: 'EUR' }).toFormat('0,0')
Expand Down

0 comments on commit 9b2990d

Please sign in to comment.