【问题标题】:How to format currency number with proper positioning and fraction after decimals in Velocity template file?如何在 Velocity 模板文件中以正确的位置和小数后的分数格式化货币数字?
【发布时间】:2019-08-11 00:03:19
【问题描述】:

我正在使用速度模板来生成 pdf 文件。在此,我必须以 7,242.84 美元或 0.00 美元或 410.70 美元等格式显示货币金额。我正在使用 NumberTool 类,在 .vm 文件中我使用的是 $number.format("###0.00",$amount) 之类的东西。

如果金额为 7242.8423 但如果金额为 0.00 则它会打印 $ 0 如果金额为 410.70,则为 410.7 美元。

请告诉我如何在此处使用正确的格式。

【问题讨论】:

    标签: java spring-mvc velocity-template-language


    【解决方案1】:

    Java 已经根据语言环境定义了多种数字/货币格式。请参阅以下内容以获取详细信息。

    https://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html

    【讨论】:

      【解决方案2】:

      我不确定velocity 模板,但您应该寻找类似下面的内容

      System.out.format("%.2f", 0.00f); //To ensure that it has two decimals or
      System.out.format("%f", 0.00f);   
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-07
        • 2020-10-25
        • 2015-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多