Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Number format in JSTL  RSS feed

 
Rithanya Laxmi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I'm working on a part of JSTL where i have to format a given number to an Indian format. I need to format a number like 999999999 to 99,99,99,999. So far i have tried to use the below code:-

<c:set var="val" value="999999999" />
<fmt:setLocale value="en_IN"/>
<fmt:formatNumber value="${val}" />

but it gives the output as 999,999,999. Your help is highly appreciated.

Thanks.
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the problem with DecimalFormat.
You have to use NumberFormat.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does putting Java code in the JSP have to do with JSTL? Java code should no longer be placed in a JSP as of 2001; please do not advise bad practices.
 
Paul Clapham
Sheriff
Posts: 22503
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the documentation for the fmt:formatNumber tag: tag documentation. I'm guessing your problem is that you want a non-standard number of digits in each comma group. The only hope for that would be the "pattern" parameter; if I'm not mistaken that would be a string which you could pass to the DecimalFormat class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!