Did you know LQ has a Linux Hardware Compatibility List?
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org assigning a large float number in E notation
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 05-09-2005, 11:17 AM #1 edM Member   Registered: Nov 2003 Location: U.K. Distribution: Slackware-12 Posts: 137 Rep: assigning a large float number in E notation hi, how do you assign a large flatoing point number in C, is the syntax below correct? float number1 = 2.302E-12; //delcare & assign . . . . printf("%f", number1); when i went to print it out all i got was '0.000000' thanks
 05-09-2005, 12:03 PM #2 enemorales Member   Registered: Jul 2004 Location: Santiago, Chile Distribution: Ubuntu Posts: 410 Rep: Code: ` float number1 = 2.302E-12` Well, this is actually a very SMALL number: about 0.000000000002302, to be more precise. This is because you put a MINUS (E-12) . Did you mean 2.302E12? (Which i think it is also 2.302E+12)
05-09-2005, 12:03 PM   #3
Hko
Senior Member

Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep:
Re: assigning a large float number in E notation

Quote:
 Originally posted by edM float number1 = 2.302E-12; //delcare & assign [...] printf("%f", number1); when i went to print it out all i got was '0.000000'
printf()'s defaults to 6 digits after the decimal point for "%f " conversion. And 2.302E-12 is smaller than 0.000000, so it's rounded to zero.

Either printf if in E-notatation:
Code:
`printf("%E\n", number1);`
Or specify how much digits after the decimal point should be output (precision), e.g. to get 15 digits:
Code:
`printf("%.15f\n", number1);`

Last edited by Hko; 05-09-2005 at 12:05 PM.

 05-09-2005, 12:51 PM #4 edM Member   Registered: Nov 2003 Location: U.K. Distribution: Slackware-12 Posts: 137 Original Poster Rep: enemorales yes i meant large as in small. thanks both you, very helpful!