Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Put minus sign in front of currency symbol formatting negative amounts #1264

Merged
merged 2 commits into from
Feb 13, 2020

Conversation

cejaekl
Copy link
Contributor

@cejaekl cejaekl commented Feb 6, 2020

Description

Fixes #1234

Changes the output of i18n.formatCurrency(-3.25) from $-3.25 to -$3.25, to conform with our new currency formatting guidelines:

https://polaris.shopify.com/foundations/formatting-localized-currency

Type of change

Changes react-i18n's i18n.formatCurrency().

  • react-i18n Patch: Minor change in formatting output. Really too small to be considered "breaking".
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above

@cejaekl cejaekl force-pushed the format_currency_minus_signs_2020-02-06 branch 3 times, most recently from 90aac42 to 5de444c Compare February 7, 2020 20:55
@cejaekl cejaekl requested review from a team and winterweix February 7, 2020 22:14
…mounts

(Placate lint)

(Fix duplicated test names)

(Updated CHANGELOG.md)
@cejaekl cejaekl force-pushed the format_currency_minus_signs_2020-02-06 branch from 5de444c to 2c0e30e Compare February 11, 2020 15:37
? `${shortSymbol.symbol}${formattedAmount}`
: `${formattedAmount}${shortSymbol.symbol}`;

return amount < 0
? `-${formattedWithSymbol.replace('-', '')}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any possible formats of formattedWithSymbol where a - would denote something that is not a minus symbol? I see 1 234,56 Kč CZK, could there ever be a format of money that would result in 1 234,56 foo-bar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're "safe" to do this.

  • We should always have - as the minus sign. Looking at the Unicode CLDR data, every single locale for which it defines a minus_sign: uses -
  • We should never have a - in this string that isn't a minus sign. We're dealing with the "symbol" for the currency, or potentially the ISO-4217 currency code (which is guaranteed to be three alphabetic letters).

It's possible that a - might show up in the full-text name of the currency (e.g. Guinea-Bisseau franc), but we won't have the full name here, only the symbol or the three-letter code.

@cejaekl cejaekl merged commit c0b72ca into master Feb 13, 2020
@vsumner vsumner deployed to just-use-act-beta February 14, 2020 16:44 Active
@helloneele helloneele temporarily deployed to production February 14, 2020 16:54 Inactive
@helloneele helloneele deployed to beta-test-reacti18n-memory-leak-fix February 20, 2020 20:41 Active
@carysmills carysmills deployed to beta-test-formatting-12-hr-dates February 26, 2020 19:32 Active
@helloneele helloneele deployed to test-use-memoized-number-format March 6, 2020 19:25 Active
@michenly michenly temporarily deployed to gem March 24, 2020 21:43 Inactive
@BPScott BPScott deleted the format_currency_minus_signs_2020-02-06 branch May 22, 2021 00:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-i18n negative currency issue
6 participants