Gustavo,
If you are working with monetary values and accuracy is important, you 
should use the java.math.BigDecimal class to perform operations 
(add,subtract,multiply, and divide) on them. Otherwise, you will introduce 
rounding errors into your intermediate calculations.
Another technique is to convert the amounts into the smallest unit of the 
currency being used so the amounts are treated as integral values. For U.S. 
dollars for example this would be cents or 0.01 dollars.  You can then use 
the NumberFormat.getCurrencyFormat() to get a NumberFormat
object for displaying the result.

-Richard


At 03:50 PM 8/29/01 -0300, you wrote:
>Hi folks.. It's me again..
>
>What's the best way for me to work with currency values in Java?
>
>I need to multiply some money values such as $ 254,00 with values like
>0.526835 ...
>
>I'm trying to work with double, but at the end I get as result a number like
>167.683625
>
>How do I work with 2 decimal digit values?
>
>thanks
>
>--
>Gustavo Gallas
>Programador
>Advice NetBusiness - Sua Melhor Intera��o com o Mundo
>advicenet.com.br
>Tel: (21) 2515.5099 - Fax: (21) 2515.5098
>
>===========================================================================
>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