Open orj opened 1 week ago
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.
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)) }
.