How to customize number format in freemarker?

前端 未结 5 505
渐次进展
渐次进展 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 18:00

    If you want to maintain the default currency formatting (in case you need to use a locale other than '$'), you can just replace the parentheses like so:

    ${transaction.amount?string.currency?replace("(","-")?replace(")","")}
    

    This will work without error regardless of if a number is negative or positive.

    TIP: Make sure the number is actually a number with the ?number directive before converting to a currency format

提交回复
热议问题