Reputation: 1360
I'm struggling a bit with the play 2.0 templating system; I have a method that returns what in scala is an 'Int' and I want to format it using the pattern "#,###".
I have tried @order.itemCount().format("#,###")
and @( order.item.count() format "#,###" )
but no love.
I'm not sure if there's a trick to this in the play template syntax or whether I just need to learn how to do this in Scala.
Upvotes: 8
Views: 3383
Reputation: 3908
What about this one:
<td>@("%.2f".formatLocal(lang().toLocale(), variable.getAverage()))</td>
Upvotes: 0
Reputation: 139038
The most straightforward approach would be to use Java's string formatting:
scala> val n = 1000000
n: Int = 1000000
scala> "%,d".format(n)
res0: String = 1,000,000
This will also handle localization correctly:
scala> String.format(java.util.Locale.ITALY, "%,d", n: java.lang.Integer)
res1: java.lang.String = 1.000.000
Upvotes: 6