Firstly, I am using a formulae to get the amount balance of money at the end of some year. The answer that i am getting is like this> $45780.19845673344 and on and on....how do i get it like $45780.00 only?
And is that the reason why i am getting the incorrect value of my answer?
Hope any of you here can clarify for me. Thank you.
well, you're already importing the java.text.DecimalFormat class (although the import statement you're using for it is a little odd-looking; if it were me, i'd just "import java.text.*". that might be just preference, though), and i'd say that's a good start. have you tried looking up DecimalFormal in the API documentation to see if there might be any useful methods in it?
There are two things to consider. First, using doubles means you're using approximations of decimal values; your calculations will be inexact. You can use BigDecimal to get exact decimal values or limit your calculations to a specified number of decimal places (typically two for money).
If you use a BigDecimal, it will output only the precision you specify, so you wouldn't need to use DecimalFormat/NumberFormat. It looks like you're not anyway, though you import any of its inner class (probably a typo, as M Beck pointed out).