Deprecated: Use the number_format
setting and the
string
built-in instead. For formatting for
computer audience (i.e., no localized formatting) use the c
built-in (like
number?c
).
Synopsis
#{expression}
or#{expression; format}
Where:
-
expression
: expression that can be evaluated as a number. -
format
: optional format specifier.
Description
The numerical interpolation is used to output a number value. If the expression doesn't evaluate to a number, the evaluation ends with an error.
The optional format specifier specifies the minimum and the
maximum number of displayed fractional digits using syntax
mminMmax
.
For example, m2M5
means "at least two, at most
five fractional digits". The minimum or the maximum specifier part
can be omitted. If only the minimum is specified, the maximum is
equal to the minimum. If only maximum is specified, the minimum is
0.
The decimal separator character of the output is internationalized (according the current locale setting), which means that it is not necessarily a dot.
Unlike ${...}
, #{...}
ignores the number_format
setting. This is actually a backward compatibility quirk, but
it can be useful when you print numbers in situations like
<a href="queryDatabase?id=#{id}">
, where
you surely don't want grouping separators or something fancy like
that. However, starting from FreeMarker 2.3.3 rather use the ?c
built-in for
this purpose, like <a
href="queryDatabase?id=${id?c}">
.
Examples. Assume that x
is
2.582
and y
is
4
:
<#-- If the language is US English the output is: --> #{x} <#-- 2.582 --> #{y} <#-- 4 --> #{x; M2} <#-- 2.58 --> #{y; M2} <#-- 4 --> #{x; m1} <#-- 2.6 --> #{y; m1} <#-- 4.0 --> #{x; m1M2} <#-- 2.58 --> #{y; m1M2} <#-- 4.0 -->