In Freemarker, how can I use a custom NumberFormat or DateFormat for 1 row (but not for the rest of the report)?

I have 2 numbers that I want to display in the freemarker file:

  • Benchmark long id

  • Check Point long timeSpend

The id should use the NumberFormatdefault instance , but timeSpend should use my instance MillisecondsSpendNumberFormat, so I get something like this in the output:

  • id: 1 234 567

  • timeSpend: 1min 23sec 456ms

How to use instance NumberFormatfor instance 1 long, but not for all of them?

+3
source share
2 answers

Freemarker ( , , ), format() .

-

timeSpend: ${myCustomFormatter.format(timeSpend)}
+4

${someNumber?string("somePattern")} , , . , FreeMarker DecimalFormat , . , MillisecondsSpendNumberFormat , . , MillisecondsSpendNumberFormat Java API TemplateMethodModelEx, , #include -d/#import -d <#assign formatTimeSpent = "com.example.MyTimeSpentFormatter"?new()>, ${formatTimeSpent(someNumber)} .

+1

All Articles