Repository navigation
Conversation
|
Overall it looks good. Except, I suspect we need format parameters here actually, to tell min/max digits for non- Also, the default number format uses |
|
Agreed on the default: with no parameters, non- For the parameters (which would only affect non- A) Underscore flags, like Consistent with the existing built-in formats and keeps B) More readable and extensible, but a new convention for built-in format names, and Also: as |
|
Because this formatting really only meant to apply to As of the format string, it could be like We could still have a shorthand like As of division, we can only document it... With this formatter, one should use an |
… scale of BigDecimal-s, and so shows trailing 0-s
|
Thanks, I've pushed a commit that does this:
|
745147c to
29f4c87
Compare
…now formatted with a nested number format, which is "number" by default, and can be specified like "scalePreserving|<otherFormat>", or limited to some fraction digits like "scalePreserving_<min>_<max>"
29f4c87 to
587a83c
Compare
https://issues.apache.org/jira/browse/FREEMARKER-232
Standard formatting drops trailing zeros of BigDecimal-s (
new BigDecimal("1.500")prints as1.5).This adds a new built-in number format name,
scalePreserving, that shows exactly as many fractiondigits as the BigDecimal's scale specifies. Usage:
${x?string.scalePreserving}, orcfg.setNumberFormat("scalePreserving"). The implementing factory,ScalePreservingTemplateNumberFormatFactory, is public, so it can also be registered as a customformat under an application-specific name.
Numbers that aren't BigDecimal-s have no scale, so they are formatted with a nested number format.
That's
numberby default, and can be specified in the format string:scalePreserving|<otherFormat>, where<otherFormat>is any number format string, likescalePreserving|0.00##.scalePreserving_<max>, orscalePreserving_<min>_<max>: likenumber, but with the givenminimum and maximum fraction digits. Works with
?stringtoo, like${x?string.scalePreserving_2_6}.?coutput is intentionally unchanged, as it's meant to be canonical. Note thatscalePreserving,and strings starting with
scalePreserving|orscalePreserving_, previously parsed as(nonsensical) DecimalFormat patterns, so recognizing them is a minor behavior change — same
precedent as
cin 2.3.32.As BigDecimal division in templates uses a scale of at least 12,
${6 / 2}prints as3.000000000000with this format. That's only documented, along with what to do about it.Includes unit tests, Javadoc, and Manual updates (settings reference,
?stringbuilt-in, customformats chapter, 2.3.36 changelog).
(I couldn't comment on the Jira issue, as I don't have an ASF Jira account yet.)