You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There currently appears to be a gap in the implementation of the FormatStyle APIs and foundation's NumberFormatter.
Although DescriptiveNumberFormatConfiguration.Presentation defines ordinal and spellOut there doesn't appear to be any presentation() APIs on IntegerFormatStyle or DecimalFormatStyle that take this type.
What this means is that if we want to format numbers 1, 2, 3, etc. in the style of "1st, 2nd, 3rd" etc we have to use NumberFormatter instead of [1, 2, 3].map { $0.formatted(.number.presentation(.ordinal)) }.
The text was updated successfully, but these errors were encountered:
It was intentional to leave them out for FormatStyle. Supporting ordinal and spell out numbers requires more context than what this API knows. For example, many languages have gendered ordinals, e.g. in Portuguese, "first" can be either "primeiro" or "primeira", and even in abbreviations ("1º", "1ª"). What we've seen in the past is that developers tend to use the formatted number as part of a localized string and caused grammatical errors. Not saying it's not doable, but it just requires more thought.
I bumped into this issue recently and used this gist to get me through. I didn't realise this had potential to be grammatically problematic. Hoping someone smarter than me can figure out how to solve this soon.
There currently appears to be a gap in the implementation of the
FormatStyle
APIs and foundation'sNumberFormatter
.Although
DescriptiveNumberFormatConfiguration.Presentation
definesordinal
andspellOut
there doesn't appear to be anypresentation()
APIs onIntegerFormatStyle
orDecimalFormatStyle
that take this type.What this means is that if we want to format numbers 1, 2, 3, etc. in the style of "1st, 2nd, 3rd" etc we have to use
NumberFormatter
instead of[1, 2, 3].map { $0.formatted(.number.presentation(.ordinal)) }
.The text was updated successfully, but these errors were encountered: