In my velocity templates, I've been using the Velocity NumberTool to format number variables as a currency. Most of these are primitive doubles and they work fine with this tool.
However, some are of type BigDecimal and they don't seem to be formatted at all. It'll just show the expression as is when rendered:
$global.numberTool.currency($someBigDecimalVariable)
Is there a convenient way to format a BigDecimal with Velocity as a currency? What are the alternatives?
Since you can put any object into a Velocity context, the easiest thing to do is to put your own DecimalFormat
object in your context and call its format()
method in the template.
Of course this isn't a very nice solution but you can refine it to make it more generic.