File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Surprising output,can't understood. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Surprising output,can Watch "Surprising output,can New topic

Surprising output,can't understood.

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

When i run the following program it prints 12.123457 and please explain this why 12.123457.
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
when a values is assigned to Float class , internally it stores to the float primitive. So i guess the precision of the primitive float comes into the picture.
If somebody can throw some more light !!

My Techie Blog - Java Questions
Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
as Harshit said this is more to deal with memory allocated with the floating point variable....

any more thoughts ....

My Thoughts :
Try not to become a man of success but rather to become a man of value.
marc weber

Joined: Aug 31, 2004
Posts: 11343

That's exactly right. This loss of precision is a result of how floating-point values are stored.

See Some things you should know about floating-point arithmetic.
[ April 20, 2008: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Surprising output,can't understood.
It's not a secret anymore!