Daniel Dekany
2015-09-13 11:20:14 UTC
Because not many people are here yet, it will be lazy vote. Is that
OK? 72 hours to go, unless there will be an active discussion of
course.
We had some RFE-s in past, where someone requested:
- Using half-up rounding mode instead of the Java default half-even
(https://sourceforge.net/p/freemarker/feature-requests/62/)
- Overriding the symbol used for NaN
(https://sourceforge.net/p/freemarker/feature-requests/67/)
- Using dot as decimal separator for certain numbers, instead of
the locale default (which was comma there) (but not the case of ?c)
(https://sourceforge.net/p/freemarker/feature-requests/117/)
I remember some other case (maybe it was just e-mail) where the user
has complained that in general he can't use all the features of
java.text.DecimalFormat as we only allow specifying the pattern
string.
The number format is specified with a string in FreeMarker. This is so
in the Configurable API, also in FTL (<#setting number_format="0.##">
and n?string("0.##")). So I wondered how to allow specifying the
parameters for DecimalFormat without making a mess, and found that we
can just extend the string parsed by DecimalFormat with a new section,
that would cause IllegalArgumentException if you pass it to
DecimalFormat as is, so it's backward compatible to add such a
section.
DecimalFormat accepts almost all kind of random string without
complaining. But it's string about ';'. DecmialFormat allows you to
specify two patterns, one for the positive, and another for the
negative numbers, separated by ';'. We could allow yet another ';' and
a further section, where the properties of the Decimal format can be
specified. So if someone wants '_' for grouping separator and half-up
rounding mode, then instead of ",##0.##", he could use ",##0.##;;
grp=_ ro=hu". The double ";;" is because the 2nd section (for negative
number format) is empty. (This is backward compatible, as that's an
error for pure DecimalFormat.) In general, the 3rd section will be a
list of key=value pairs separated by whitespace and and optional
comma. If a value needs quoting, the quotation rules of DecimalFormat
patterns will be used (i.e, use apostrophe-quote, and double it for
escaping). The allowed keys would be:
- ro=u|d|c|f|hu|hd|he|un: RoundingMode
- mul: Multipier
- dec: DecimalSeparator
- grp: GroupingSeparator
- exp: ExponentSeparator
- min: MinusSign
- inf: Infinity
- nan: NaN
- prc: Percent
- prm: PerMill
- zero: ZeroDigit
- curc: Currency (ISO 4217 Code)
- curs: CurrencySymbol 2nd
- icurs: InternationalCurrencySymbol
- mdec: MonetaryDecimalSeparator
I will add this feature, if you agree.
OK? 72 hours to go, unless there will be an active discussion of
course.
We had some RFE-s in past, where someone requested:
- Using half-up rounding mode instead of the Java default half-even
(https://sourceforge.net/p/freemarker/feature-requests/62/)
- Overriding the symbol used for NaN
(https://sourceforge.net/p/freemarker/feature-requests/67/)
- Using dot as decimal separator for certain numbers, instead of
the locale default (which was comma there) (but not the case of ?c)
(https://sourceforge.net/p/freemarker/feature-requests/117/)
I remember some other case (maybe it was just e-mail) where the user
has complained that in general he can't use all the features of
java.text.DecimalFormat as we only allow specifying the pattern
string.
The number format is specified with a string in FreeMarker. This is so
in the Configurable API, also in FTL (<#setting number_format="0.##">
and n?string("0.##")). So I wondered how to allow specifying the
parameters for DecimalFormat without making a mess, and found that we
can just extend the string parsed by DecimalFormat with a new section,
that would cause IllegalArgumentException if you pass it to
DecimalFormat as is, so it's backward compatible to add such a
section.
DecimalFormat accepts almost all kind of random string without
complaining. But it's string about ';'. DecmialFormat allows you to
specify two patterns, one for the positive, and another for the
negative numbers, separated by ';'. We could allow yet another ';' and
a further section, where the properties of the Decimal format can be
specified. So if someone wants '_' for grouping separator and half-up
rounding mode, then instead of ",##0.##", he could use ",##0.##;;
grp=_ ro=hu". The double ";;" is because the 2nd section (for negative
number format) is empty. (This is backward compatible, as that's an
error for pure DecimalFormat.) In general, the 3rd section will be a
list of key=value pairs separated by whitespace and and optional
comma. If a value needs quoting, the quotation rules of DecimalFormat
patterns will be used (i.e, use apostrophe-quote, and double it for
escaping). The allowed keys would be:
- ro=u|d|c|f|hu|hd|he|un: RoundingMode
- mul: Multipier
- dec: DecimalSeparator
- grp: GroupingSeparator
- exp: ExponentSeparator
- min: MinusSign
- inf: Infinity
- nan: NaN
- prc: Percent
- prm: PerMill
- zero: ZeroDigit
- curc: Currency (ISO 4217 Code)
- curs: CurrencySymbol 2nd
- icurs: InternationalCurrencySymbol
- mdec: MonetaryDecimalSeparator
I will add this feature, if you agree.
--
Thanks,
Daniel Dekany
------------------------------------------------------------------------------
Thanks,
Daniel Dekany
------------------------------------------------------------------------------