0

I am using velocity template for generating pdf file. In this I have to show currency amount in the format like $ 7,242.84 or $ 0.00 or $ 410.70. I am using NumberTool class and in .vm file I am using something like $number.format("###0.00",$amount).

This is working fine in case if amount is 7242.8423 but if amount is 0.00 then it prints $ 0 if amount is 410.70 then $ 410.7.

Please tell me how I can use a proper formatting here.

Shashi Shekhar
  • 177
  • 1
  • 4
  • 16

2 Answers2

0

Java already defines multiple number/currency formats based on locale. Please see the following to get the details.

https://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html

vavasthi
  • 922
  • 5
  • 14
0

I am not sure about velocity template but you should look for something like below

System.out.format("%.2f", 0.00f); //To ensure that it has two decimals or
System.out.format("%f", 0.00f);   
Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41