Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
 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!

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post nadroj Programming 6 07-11-2005 04:52 PM msteudel Linux - General 4 01-26-2005 01:36 AM keefaz Programming 3 06-06-2004 02:16 PM mikeshn Linux - Security 2 01-10-2004 06:11 AM RefriedBean Linux - Security 3 07-05-2002 11:34 PM

All times are GMT -5. The time now is 07:13 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -