How to customize number format in freemarker?

前端 未结 5 534
渐次进展
渐次进展 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:50

    You can also try ?string(",##0.00"). However in this case you need to explicitly add $ and - sign would be after $ in case of negative numbers.

    <#local total = 3343434/>
    $ ${total?string(",##0.00")}  //$ 3,343,434.00
    
    <#local total = -3343434/>
    $ ${total?string(",##0.00")}  //$ -3,343,434.00
    

    OR in case if you want what was expected you can replace the strings.

    <#local total = -3343434/>
    <#local total = "$ " + total?string(",##0.00")/>
    
    ${total?replace('$ -','- $')}   //- $3,343,434.00
    

提交回复
热议问题