Raj,
There is not a method that truncates a double to a certain
precision.  Check out this link for an explanation on Performing Exact
Calculations With Floating-Point Numbers

http://developer.java.sun.com/developer/JDCTechTips/2001/tt0807.html

Basically, can either use the BigDecimal class that supports arbitrary
precision numbersinstead of the double type or you can write a method that
rounds a number to the desired precision for you.

ie
/**
  * Trim a double value to two decimal points
  *
   public static double trim(double d)
   {
     BigDecimal bd = new BigDecimal(d);
     return bd.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
   }


At 09:53 PM 8/27/01 -0700, you wrote:
>Hi all,
>
>i have variable double x = 34.8976 ;
>i want only 2 digits after decimal. Is there any method  returning double
>and gives value x = 34.89 ???
>
>Cheers!!
>Raj
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to