Results 1 to 2 of 2

Thread: floating point issue.Why is it so?

  1. #1
    Join Date
    Dec 2010
    Posts
    1

    floating point issue.Why is it so?

    Hey all ,
    Please run the below program and see the output you get. It gives the output as 1.2 when i change the parameter in the place of 1.2 as 1.1.Similarly it gives 1.4 when i enter 1.3 in place of 1.2. It works for al inputs but when I enter 1.2 it outputs 1.300001. Why is it so?
    Code:
    public class test1 {
    
    	
    	public static void main(String[] args) {
    	
    		float existVersion = Float.parseFloat("1.2");
    		float NewVersion = (float) (existVersion + 0.1);
    		
    
    		String newVersion=String.valueOf(NewVersion);
    		
    		System.out.println(newVersion);
    
    	}
    
    }

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: floating point issue.Why is it so?

    I guess that it is static because otherwise the JVM would have to instantiate an instance of <MainClass>, and therefore would have to know that MainClass had a default constructor...all to simply get the app started up. Whereas with a static main it knows that MainClass.main(args) should exist, and all it has to do is load the class.

Similar Threads

  1. Replies: 3
    Last Post: 28-06-2012, 04:31 PM
  2. C++ error "floating point support not loaded"
    By addie in forum Software Development
    Replies: 4
    Last Post: 23-12-2011, 07:33 PM
  3. Replies: 6
    Last Post: 12-07-2011, 11:14 AM
  4. Replies: 5
    Last Post: 11-07-2011, 10:38 AM
  5. Replies: 5
    Last Post: 11-03-2010, 05:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,549,390.15295 seconds with 17 queries