That depends on what your requirements are. If the lack of exact accuracy isn't a problem, and all you need is the output to look a bit more predictable, you can use DecimalFormat to produce output to the precision you want.
You sound like you think that is a bad thing. Writing code is like building a house. You need to use the right tool for the job. It seems like you're saying "I want to drive in this nail. Can I use a wrench".
you're told to use a hammer.
You the reply with "well, I can use this really, really big wrench".
If BigDecimal is the right tool, why don't you want to use it?
Joined: May 13, 2010
Its not like that,I just wanted to make sure.
I used BigDecimal in my code but still facing same problem.
If you pass a double to the constructor of a BigDecimal, you will get the imprecision of double, recorded very accurately. If you want 1.2345, you need to pass the String "1.2345" to the BigDecimal constructor.