Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



printf double in c

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 26-02-2010
Member
 
Join Date: Nov 2009
Posts: 520
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.
Reply With Quote
  #2  
Old 26-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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);
Reply With Quote
  #3  
Old 26-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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);
	}
Reply With Quote
  #4  
Old 26-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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
Reply With Quote
  #5  
Old 26-02-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 26-02-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "printf double in c"
Thread Thread Starter Forum Replies Last Post
Pirates of Black Cove, no missions after ‘Double-Double Crossing’ Maee Video Games 7 28-12-2011 05:18 PM
Errors in printf() in c programming RamBarose Education Career and Job Discussions 6 27-04-2011 11:36 PM
Problem of DNS and Double-NAT visioneye Networking & Security 6 29-05-2010 07:38 AM
What is the printf() function of the C language Tailor Software Development 5 27-02-2010 04:26 PM
Double clicking. Tristan Vista Help 8 08-03-2008 11:55 PM


All times are GMT +5.5. The time now is 04:19 AM.