Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting comma inside value of long type at freemarker page

I am having some strange problem and its really frustating me. I have a list of Car bean in request attribute -

List<Car> cars = myservice.getCars();
request.setAttribute("cars", cars);

When I print the car ids (long type), it gives me correct value -

for(Car car: cars) {
 System.out.println(car.id);
}
// It gives me - 11231, 11245, 11253

But when I am trying to get same on freemarker page resutl.ftl, its giving me values as -

11,231 
11,245
11,253

The code is -

<#list cars as car>
 <span>Car Id:</span>${car.id}
<#list>
like image 398
Saurabh Avatar asked Jul 25 '10 21:07

Saurabh


1 Answers

Formatting of numbers appears to be locale-sensitive. This FAQ entry appears to give a fix:

http://freemarker.sourceforge.net/docs/app_faq.html#faq_number_grouping

From that page (and that page alone, I'd never heard of Freemarker before your question), it seems that this might do what you want:

<span>Car Id:</span>${car.id?c}

Or you could adjust your locale settings or number format to be something more like you expect. Exactly how to do that is detailed in the link above.

like image 167
Gian Avatar answered Oct 26 '22 01:10

Gian