简体   繁体   中英

Formatting numbers in Velocity Templates?

I need to display amount in following formats:

1099 -> 1,099.00

100 -> 100.00

100.251 -> 100.25

10999 -> 10,999.00

1110999 -> 11,10,999.00

Right now I am using following code to display amount:

$numberTool.format("#0.00", $credit);

In this case, if amount is 1099, then it displays 1099.00 but I want to display this amount in this format:- 1,099.00

您缺少对分组分隔符的处理:

$numberTool.format("###,##,###.00", $credit);

Check this :

NumberFormat nf = new DecimalFormat("##,##,###.00");
System.out.println(nf.format(1099));

Output :

1,948.00

Is it what you are wanting.

you can solve this problem like this

#set ($result = $number.format('#,##0.00', "10000.5"))
$result

The result will be 10,000.50

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM