May 28, 2007 #1 lovekang Programmer Joined Feb 16, 2006 Messages 86 Location KR public static void main(String args[]) { System.out.println(0.1); // 0.1 System.out.println(0.7); // 0.7 System.out.println(0.1 + 0.7); // 0.7999999999999999 } I expect 0.1, 0.7 and 0.8 why this happens? thanks.
public static void main(String args[]) { System.out.println(0.1); // 0.1 System.out.println(0.7); // 0.7 System.out.println(0.1 + 0.7); // 0.7999999999999999 } I expect 0.1, 0.7 and 0.8 why this happens? thanks.
May 29, 2007 #2 prosper Programmer Joined Sep 4, 2001 Messages 631 Location HK //try this System.out.println(0.1f + 0.7f); // 0.7999999999999999 Upvote 0 Downvote
May 29, 2007 Thread starter #3 lovekang Programmer Joined Feb 16, 2006 Messages 86 Location KR Thanks. I'm wondering why this happens? Upvote 0 Downvote
May 29, 2007 #4 Diancecht Programmer Joined Jan 8, 2004 Messages 4,042 Location ES Well, it's an all computing matter: you cannot represent all numbers with a finite number of bytes. http://forum.java.sun.com/thread.jspa?threadID=386078&messageID=1660010 Cheers, Dian Upvote 0 Downvote
Well, it's an all computing matter: you cannot represent all numbers with a finite number of bytes. http://forum.java.sun.com/thread.jspa?threadID=386078&messageID=1660010 Cheers, Dian