Float data type issue

This is a discussion on Float data type issue within the C Programming forums, part of the General Programming Boards category; Float data type outputs the data with 6 decimal points(like 5.00000) even the number doesn't have any decimal points.Why is ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    20

    Float data type issue

    Float data type outputs the data with 6 decimal points(like 5.00000) even the number doesn't have any decimal points.Why is that so?Can it just output the necessary decimals?



    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    
    main()
    
    {
    	
    	
    	float a,b,c,x;
    	printf("Use this to work out the length of the hypotenuse on a right angled triangle.\n");
    	printf("Please enter a:");
    	scanf("%f",&a);
    	printf("\nPlease enter b:");
    	scanf("%f",&b);
    	
    	// a*a+b*b=c*c;
    	
    	x=a*a+b*b;
    	c=sqrt(x);
    	
    	printf("\nThe triangle's hypotenuse has a length of %f ",c);
    	
    	getch();
    	
    	return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Use %g instead of %f.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    20
    That's cool.Thanks,tabstop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined reference to.. probably Makefile problem
    By mravenca in forum C Programming
    Replies: 11
    Last Post: 10-20-2010, 05:29 AM
  2. Matrix operations using objects
    By circuitbreaker in forum C++ Programming
    Replies: 7
    Last Post: 05-04-2010, 09:53 AM
  3. Code review
    By bennywhere in forum C Programming
    Replies: 16
    Last Post: 10-20-2009, 10:00 PM
  4. Replies: 14
    Last Post: 06-28-2006, 02:58 AM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 01:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21