i18n
i18n copied to clipboard
Add getters to `NumberFormat` for calculated config properties
Is your feature request related to a problem? Please describe.
Certain properties on NumberFormat
objects behave or are configured differently, according to the specific use case. For example, the decimalDigits
field is documented as so:
/// If this is not explicitly specified in the constructor, then for
/// currencies we use the default value for the currency if the name is given,
/// otherwise we use the value from the pattern for the locale.
Thus, calling the decimalDigits
getter on a NumberFormat
instance may not actually tell you the actual number of decimal digits that will be used during formatting.
Other properties are hidden for some reason, such as _isCurrency
.
I have use cases where it would be very helpful to be able to know exactly how many decimal digits will end up being used in formatting, or whether the format instance is formatting for currencies or not, and would like to be able to have access to these pieces of configuration information.
Describe the solution you'd like Add getters for hidden or calculated fields
Additional context
One example of an issue I'm trying to solve is using precise number types (for example, [Decimal](https://pub.dev/packages/decimal)
rather than double
) for currencies in form fields, and I'm using NumberFormat
to create a TextInputFormatter
for this use case. However, because parse
returns a num
which could be an imprecise double
, I'd like to keep track of the entire series of digits as an int
, and then create the correct Decimal
by dividing by the appropriate power of ten according to the number of decimal digits the formatter is using. Because the logic determining that value's can depend on several variables, the precise value used during formatting is not readily available and can result in bugs.