My temp.txt show me 1.3487e-02 but I need 0.013487.Code:
// Matrizo: Dynamic Float Matrix
// i, j : integer;
// pFile: FILE*
...
fprintf (pFile, "%i %i %g\n",i,j,matrizo[i][j])
...
Someone can help me plz?
Tks ^^
Printable View
My temp.txt show me 1.3487e-02 but I need 0.013487.Code:
// Matrizo: Dynamic Float Matrix
// i, j : integer;
// pFile: FILE*
...
fprintf (pFile, "%i %i %g\n",i,j,matrizo[i][j])
...
Someone can help me plz?
Tks ^^
fprintf (pFile, "%i %i %f\n",i,j,matrizo[i][j])
Hacker2 tks for your answer ^^Quote:
Originally Posted by Hacker2
But I really need the shorter version, with %f I'll have "0" after the number, thats why I'm using %g.
You can specify the number of decimal place to be displayed.
Code:fprintf (pFile, "%i %i %0.6f\n",i,j,matrizo[i][j]);
Here is a complete spec of all the ways you can specify formatting
http://www.cplusplus.com/ref/cstdio/printf.html
Kheun, I really need the numbers without "0", the way you told me will have sometimes unecessary "0" after:Quote:
Originally Posted by Kheun
Ex.:
0.500000
0.256000
...
But tks very much for your answer ;)
Tks very much Hacker2 ^^...Quote:
Originally Posted by Hacker2
I saw the page and I dont think there is a way to show the way I need.. I'll have to go by the "hard" way..
Tks everyone :)
You could remove the trailing zeros manually:
Code:char temp[100];
sprintf(temp, "%f",matrizo[i][j]);
int k = strlen(temp);
if(k > 0) k--; //avoid zero-length string problems
while(temp[k]=='0' && k > 0){
temp[k]=0;
k--;
}
fprintf (pFile, "%i %i %s\n",i,j,temp);