The problem occurred originally with Tools v1.3 - I noticed that this
was old news so I updated to v1.4 and the same problem occurred - that
was when I decided it was time for an email to the list.
As I mentioned - single quotes to the rescue - the simple solution is
the best.
Cheers,
J --
On Apr 21, 2008, at 11:08 AM, Nathan Bubna wrote:
Looks like it. I'm still curious what version it was with.
On Mon, Apr 21, 2008 at 9:01 AM, csanders <[EMAIL PROTECTED]>
wrote:
So what was velocity doing ?
Some problem with pound signs in double quotes ??
Jason Chodakowski wrote:
Ahh - brilliant. Problem solved.
Thanks,
J --
On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
Yeah, doesn't look like NumberTool has the problem. Velocity
must be
doing something funky with those # signs. Try defining those
strings
with single quotes so that they aren't interpolated. Really, as a
general rule, if you don't need strings to be interpolated
(parsed as
if they were mini-templates), then you should single quote them
instead of double quote.
$NT.format('#,##0.##','190.0')
And for the record, which version of Velocity is this with?
On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
<[EMAIL PROTECTED]> wrote:
I should also add that I also tried this in my tests:
NumberTool nt = new NumberTool();
Double dbl = new Double("190.00");
System.out.println(nt.format("#,##0.##", dbl));
This does not produce the IOException so it seems to be an
artifact of
template rendering.
Hope that helps.
Thanks,
J --
On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
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 --
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]