Re: How to format number

2003-10-07 Thread Boris Folgmann
Lee Chin Khiong wrote:
 How to format a double in JSP or java ?
 
 for example :
 
 10/3=3.3
 
 I want to format it to 3.33.

Try realToString(3.33, 2) with this:

/** Convert a float to a string with fixed number of fraction digits
 */
public static String realToString(float f, int numFracDigits, Locale
locale)
{
NumberFormat fmt = NumberFormat.getInstance(locale);
fmt.setMaximumFractionDigits(numFracDigits);
fmt.setMinimumFractionDigits(numFracDigits);
return fmt.format(f);
}

or for default locale:

/** Convert a float to a string with fixed number of fraction digits
 */
public static String realToString(float f, int numFracDigits)
{
NumberFormat fmt = NumberFormat.getInstance();
fmt.setMaximumFractionDigits(numFracDigits);
fmt.setMinimumFractionDigits(numFracDigits);
return fmt.format(f);
}


-- 
Dipl.-Inf. Boris Folgmann   mailto:[EMAIL PROTECTED]
TeamForge GmbH  http://www.teamforge.de
-m-o-d-w-a-r-s- http://www.modwars.de


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to format number

2003-10-07 Thread Lawence
There are some non-standard nice library classes you can use for this purpose. Just 
google it. These classes enable you to format things like you are working with c/c++.
 


Lee Chin Khiong [EMAIL PROTECTED] wrote:
How to format a double in JSP or java ?

for example :

10/3=3.3

I want to format it to 3.33.



-
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Re: How to format number

2003-10-07 Thread Mark Lenz

Check out the class java.text.DecimalFormat from the j2se SDK.

Mark Lenz
Software Engineer
Control Systems Group
Pierce Manufacturing, Inc.
(920) 832-3523
[EMAIL PROTECTED]


|-+
| |   Lawence  |
| |   [EMAIL PROTECTED]|
| |   o.com   |
| ||
| |   10/07/2003 10:44 |
| |   AM   |
| |   Please respond to|
| |   Tomcat Users|
| |   List|
| ||
|-+
  
---|
  |
   |
  |   To:   Tomcat Users List [EMAIL PROTECTED]  
  |
  |   cc:  
   |
  |   Subject:  Re: How to format number   
   |
  
---|




There are some non-standard nice library classes you can use for this
purpose. Just google it. These classes enable you to format things like you
are working with c/c++.



Lee Chin Khiong [EMAIL PROTECTED] wrote:
How to format a double in JSP or java ?

for example :

10/3=3.3

I want to format it to 3.33.



-
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search


This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com




The information contained in this electronic mail message is confidential
information and intended only for the use of the individual or entity named
above, and may be privileged.  If the reader of this message is not the
intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.  If
you have received this transmission in error, please  contact the sender
immediately, delete this material from your computer and destroy all
related paper media.  Please note that the documents transmitted are not
intended to be binding until a hard copy has been manually signed by all
parties.
Thank you.




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: How to format number

2003-10-07 Thread Zhang, Hong
Try to use java.text.NumberFormat
NumberFormat nf= NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
Double number = 10/3;
String snumber = nf.format(number);

-Original Message-
From: Lawence [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 07, 2003 11:44 AM
To: Tomcat Users List
Subject: Re: How to format number


There are some non-standard nice library classes you can use for this
purpose. Just google it. These classes enable you to format things like
you are working with c/c++.
 


Lee Chin Khiong [EMAIL PROTECTED] wrote:
How to format a double in JSP or java ?

for example :

10/3=3.3

I want to format it to 3.33.



-
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: RE: How to format number

2003-10-07 Thread budi
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;http://java.sun.com/jsp/jstl/fmtquot; prefix=quot;fmtquot; 
%gt;
lt;fmt:formatNumber value=quot;0.3quot; maxFractionDigits=quot;2quot;/gt;
lt;br/gt;
lt;fmt:formatNumber value=quot;0.33533quot; maxFractionDigits=quot;2quot;/gt;
lt;br/gt;
lt;fmt:formatNumber value=quot;0.3quot; minFractionDigits=quot;2quot; 
maxFractionDigits=quot;2quot;/gt;
lt;br/gt;
lt;fmt:formatNumber value=quot;${10/3}quot; minFractionDigits=quot;2quot; 
maxFractionDigits=quot;2quot;/gt;

gives you:

0.33 
0.34 
0.30 
3.33 

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,
budi


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



Author of
- How Tomcat Works (sample chapters downloadable from www.brainysoftware.com) 
- 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)


How to format number

2003-10-06 Thread Lee Chin Khiong
How to format a double in JSP or java ?

for example :

10/3=3.3

I want to format it to 3.33.



Re: How to format number

2003-10-06 Thread Paul Gregoire
Look into the java.text package, you'll find a Number formatter there.. or
if you dont want a String, use Math.round()


- Original Message - 
From: Lee Chin Khiong [EMAIL PROTECTED]
To: 'Tomcat Users List' [EMAIL PROTECTED]
Sent: Monday, October 06, 2003 6:37 PM
Subject: How to format number


 How to format a double in JSP or java ?

 for example :

 10/3=3.3

 I want to format it to 3.33.




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]