LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 05-09-2005, 11:17 AM   #1
edM
Member
 
Registered: Nov 2003
Location: U.K.
Distribution: Slackware-12
Posts: 137

Rep: Reputation: 15
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
 
Old 05-09-2005, 12:03 PM   #2
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 30
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)
 
Old 05-09-2005, 12:03 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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.
 
Old 05-09-2005, 12:51 PM   #4
edM
Member
 
Registered: Nov 2003
Location: U.K.
Distribution: Slackware-12
Posts: 137

Original Poster
Rep: Reputation: 15
enemorales yes i meant large as in small.


thanks both you, very helpful!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
count digits of a float || convert float to string nadroj Programming 6 07-11-2005 04:52 PM
Deleting a large number of files msteudel Linux - General 4 01-26-2005 01:36 AM
C++ format float number output keefaz Programming 3 06-06-2004 02:16 PM
Large Number of files? mikeshn Linux - Security 2 01-10-2004 06:11 AM
Large number of open ports RefriedBean Linux - Security 3 07-05-2002 11:34 PM


All times are GMT -5. The time now is 10:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration