How to customize number format in freemarker?

前端 未结 5 501
渐次进展
渐次进展 2021-01-13 17:45

I am using freemarker and trying to display numbers in this format: $3,343,434.00 for example. This was easily taken care of by using ${total?string.curre

5条回答
  •  孤街浪徒
    2021-01-13 17:51

    Freemarker uses the currency formatting provided by the Java platform.

    It requires a little tweaking of the DecimalFormat returned by NumberFormat.getCurrencyInstance() (which is what is called when you call .currency). You can see examples of it here.

    However, that said it will likely be more effective for you to create a macro in freemarker to call which will handle your specific formatting.

    Sorry for not having an example of what that macro would look like, but it's a good starter into macros in freemarker since you are just learning.

    You might investigate if you can supply a custom format using the exposed configuration for number formats that will meet your needs.

提交回复
热议问题