Search code examples
jspformattingvelocitytemplate-engine

Is there analog of fmt:formatNumber in velocity like in jsp?


Now I am migrating my jsp to velocity template. I cannot find solution how to migrate following code line:

<fmt:formatNumber minFractionDigits='2' value='${campaign.budget div 100}'/>

Does velocity can something like this?


Solution

  • You can use $numberTool.format("#0.00", $val) You should see 'org.apache.velocity.tools.generic.NumberTool' for more details.

    To make it working you also should add the following maven dependency:

    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity-tools</artifactId>
        <version>2.0</version>
    </dependency>
    

    and write following code:

    context.put("numberTool", new NumberTool());