Subbu It's because floating point numbers are only completely accurate for numbers that are powers of 2 (e.g 1,2,4,8 going up,0.5,0.25,0.125 going down etc) and numbers that are combinations of these, e.g. 3 (2 + 1), 1.75 (1 + 0.5 + 0.25) etc.
1.1 isn't one of these numbers, so internally it will be 1.100000000000000000+a bit extra. Add enough 1.1's together and the little bits add up until they are significant. Having said that, it's odd that the last digit is a 2, i.e. if x is the little bit, then x + x + x rounds to 2 means x >= 0.5, so x + x might be expected to round to 1. regards Mark -----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of subbu Sent: 01 May 2002 13:58 To: [EMAIL PROTECTED] Subject: Amazing script hai, try this and give an explanation why this happens (JAVASCRIPT) var a,b,c,d,e a=1.1 b=1.1 c=1.1 d=a+b--------(answer is 2.2) e=a+b+c(answer is 3.30000000000002) alert(e); ========================= To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com ************************************************************************* The information contained in this message or any of its attachments may be privileged and confidential and intended for the exclusive use of the addressee. If you are not the addressee any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited ************************************************************************* =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
