如何在Play 2.0模板中格式化数字/日期? [英] how to format a number/date in play 2.0 template?

查看:88
本文介绍了如何在Play 2.0模板中格式化数字/日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在play 2.0模板系统上有点挣扎;我有一个方法可以返回scala中的"Int",我想使用模式#,###"对其进行格式化.

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 "#,###".

我尝试过@order.itemCount().format("#,###")@( order.item.count() format "#,###" ),但是没有爱.

I have tried @order.itemCount().format("#,###") and @( order.item.count() format "#,###" ) but no love.

我不确定播放模板语法中是否有此技巧,或者我是否只需要学习如何在Scala中做到这一点.

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.

推荐答案

最直接的方法是使用

这也将正确处理本地化:

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

这篇关于如何在Play 2.0模板中格式化数字/日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆