NumberTool

Last Updated: Feb 4, 2021
documentation for the dotCMS Content Management System

Tool for working with Number in Velocity templates. It is useful for accessing and formatting arbitrary Number objects. Also the tool can be used to retrieve NumberFormat instances or make conversions to and from various number types.

The following example shows how the NumberTool is mapped in the toolbox-xml file:

     <tool>
       <key>number</key>
       <scope>application</scope>
       <class>org.apache.velocity.tools.generic.NumberTool</class>
     </tool>

Example

  $myNumber                            -> 13.55
  $number.format('currency',$myNumber) -> $13.55
  $number.format('integer',$myNumber)  -> 13

This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application). As such, the methods are highly interconnected, and overriding key methods provides an easy way to create subclasses that use a non-default format or locale.

On this page

×

We Dig Feedback

Selected excerpt:

×