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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With