Hello... just this morning I needed to do some "in-template" number formatting and pulled the VelocityTools NumberTool off the shelf. Now that I'm trying to use it, I'm having some issues.

First, I've got a number tool in the context - context.put("NT", new NumberTool())

Next, I try to format a number in the template - #set($SW = $NT.format("#,##0.##", "190.00"))

The "190.00" is actually pulled from the context, but there are other tests ahead of this to make sure we've got a real value there. When the template is rendered, I get this error message:

java.io.IOException: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'format' in class org.apache.velocity.tools.generic.NumberTool threw exception java.lang.IllegalArgumentException: Malformed pattern "#," @ template.vm[57,32]
        at ...

Now what is odd about this, is that it IS a valid number format - and looking at the source of the NumberTool, it looks like it would just stuff those values into a DecimalFormat and be done with it. Is velocity choking because of the #-pound-signs?

I double checked my format with these lines:

DecimalFormat f = new DecimalFormat("#,##0.##");
System.out.println(f.format(190.00D));

And this produces the result I expect: "190"

Also, I do have the Locale in the context too - it's just the default Locale which it looks like would be picked up automatically when not specified so I've not tried this avenue.

Any thoughts on this?

Many thanks in advance.

J --

Reply via email to