This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Kasun Athukorala wrote:why isn't it giving the same input value??
Because double only has 64 bit to store its information. Your number is too large and it gets truncated.
How can i get the same output as the input??
By using BigDecimal. That's the only data type in Java that's accurate enough. Note that you should use the constructor that takes a String; don't create one from a double because the truncation will then happen before the BigDecimal is created.