LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   assigning a large float number in E notation (http://www.linuxquestions.org/questions/programming-9/assigning-a-large-float-number-in-e-notation-321679/)

edM 05-09-2005 12:17 PM

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 :)

enemorales 05-09-2005 01:03 PM

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)

Hko 05-09-2005 01:03 PM

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);

edM 05-09-2005 01:51 PM

enemorales yes i meant large as in small. :p


thanks both you, very helpful!


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