
Problems with doubles
Hi, I am making a algorithm that is very important the value of the numbers, but I have some problems, for example I need to do this operation: 1.0/14709204.0, after for I know the result of the operation I write the result of operation in one file, for example I do this:
Code:
FILE* tot = fopen("total.txt", "wb");
char buffft [2000];
sprintf (buffft,"%f",1/14709204);
fwrite(buffft,1,strlen(buffft),tot);
After I open the file total.txt I can see 0.000000, and the correct result is :6.798464417*108, I need this result, can someone help me please?any idea?
Thanks.

>1/14709204
This is an integer expression with an integer result because both operands are integers. To make it floatingpoint, change one or both of the values to double:
Code:
sprintf (buffft,"%f",1.0/14709204.0);

Gracias por la respuesta, pero hago esto que usted cuenta y el resultado es el mismo: 0.000.
¿Alguna idea?


I have written it in Spanish, this one is the translation:
Thanks for the reply, but I do this that you tell and the result is the same: 0.000.
Any idea?

Try the %g format modifier instead of %f.

Thanks, now in the file I can see 6.79846e008 (the correct result), Therefore now I that the result of my operations they are correct.. Therfore the problem of my algorithm are in the other part...jeje thanks for the fast replys.