Results 1 to 6 of 6

Thread: printf double in c

  1. #1
    Join Date
    Nov 2009
    Posts
    518

    printf double in c

    Hello !
    I am creating a simple program which requires to print the double variable.I am new guy for this programming language.I had looked from books but not getting anything.The printing statement for the Double variable has different format when we use in the programs!I am getting confused.Please suggest me a good way to do it.

    Thanks.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    printf double in c

    printf double in c

    The printf statement takes different ways to print the double data type values.
    here,I am going to show you the statement which will print the statement produced by double data type.

    Code:
    double value = 1.543605908721;
    
    printf("Value 1.3lf", value);

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    printf double in c

    C displays both type of variables float and double upon to the six decimal places. it does not need to the precision of which the number is really collected.

    The implementation of the float an double data type would be as it

    Code:
    #include <stdio.h>
    
    	main()
    	{
    		int     Add = 100;
    		char    Character = 'Z';
    		float   Adj1 = 23.567;
    		double  Number2 = 11e+23;
    
    		printf("Integer variable is %d\n", Add);
    		printf("Character is %c\n", Character);
    		printf("Float variable is %f\n", Adj1);
    		printf("Double variable is %e\n", Number2);
    	}

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    printf double in c

    The style of statement for printing Double values is very different than the other variables.You can view this output and can measure the effect of printing statement.The Printf statement behavior can be changed for the double and float variables.

    Zecho writes the code,just execute it and find out the values which would be produced due to execution.

    The output of the above program would be -

    Integer variable is 100
    Character variable is Z
    Float variable is 23.567000
    Double variable is 11.000000e23

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    setting the precision for double in c

    setting the precision :

    You can change the precision of the double type values in the program using some little bit changes in the printf statement.

    To change the behavior of decimal places places for float and double type variables, you can edit the %f or %e to add the desired precision value.


    Code:
    printf("Value of double variable is %.2e\n",Doub_var );

    You can put any desired number where 2 is placed,the output would be converted and displayed in the precision what you provide.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    DATA TYPE CONVERSION with double and float

    DATA TYPE CONVERSION

    Just look at the following program :

    Code:
    #include <stdio.h>
    
    	main()
    	{
    		int  val1 = 12, val2 = 5;
    		float result = 0;
    
    		result = val1 / val2;
    		printf("The value of %d divided by %d is %f\n",val1,val2,result );
    	}
    The result and implementation of the above declaration for different variables will work but it is not reliable manner to write the code.To find the exact result you need to covert the val1 and val2 variables into float and then try to assign them.

Similar Threads

  1. Replies: 7
    Last Post: 28-12-2011, 05:18 PM
  2. Errors in printf() in c programming
    By RamBarose in forum Education Career and Job Discussions
    Replies: 6
    Last Post: 27-04-2011, 10:36 PM
  3. Problem of DNS and Double-NAT
    By visioneye in forum Networking & Security
    Replies: 6
    Last Post: 29-05-2010, 06:38 AM
  4. What is the printf() function of the C language
    By Tailor in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 04:26 PM
  5. Double screen? not really.
    By Informant in forum Hardware Peripherals
    Replies: 2
    Last Post: 10-11-2008, 12:43 PM

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,526,985.23723 seconds with 17 queries