tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "budi" <>
Subject Re: RE: How to format number
Date Wed, 08 Oct 2003 00:38:16 GMT
In JSP, the easiest is to use the formatNumber tag of the JSTL I18N library. For example, the
following JSP page:

&lt;%@ taglib uri=&quot;; prefix=&quot;fmt&quot;
&lt;fmt:formatNumber value=&quot;0.33333&quot; maxFractionDigits=&quot;2&quot;/&gt;
&lt;fmt:formatNumber value=&quot;0.33533&quot; maxFractionDigits=&quot;2&quot;/&gt;
&lt;fmt:formatNumber value=&quot;0.3&quot; minFractionDigits=&quot;2&quot;
&lt;fmt:formatNumber value=&quot;${10/3}&quot; minFractionDigits=&quot;2&quot;

gives you:


Don't forget to copy the jstl.jar and standard.jar to your WEB-INF/lib. Also, if you are using
Tomcat 4, you can't enjoy the EL expression in the last formatNumber.

Hope this helps,

   &gt;  Lee Chin Khiong  wrote:
   &gt;  How to format a double in JSP or java ?
   &gt;  for example :
   &gt;  10/3=3.3333333333333
   &gt;  I want to format it to 3.33.

Author of
- How Tomcat Works (sample chapters downloadable from 
- JavaServer Faces Programming (McGraw-Hill Osborne Media)
- Java for the Web with Servlets, JSP, and EJB (NewRiders)
- Java Web Development with Servlets, JSP, and EJB, Second Edition (Sam Publishing)
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message