|
-
August 24th, 2005, 11:20 PM
#1
Need 0.013487 but I have 1.3487e-02
Code:
// Matrizo: Dynamic Float Matrix
// i, j : integer;
// pFile: FILE*
...
fprintf (pFile, "%i %i %g\n",i,j,matrizo[i][j])
...
My temp.txt show me 1.3487e-02 but I need 0.013487.
Someone can help me plz?
Tks ^^
-
August 24th, 2005, 11:40 PM
#2
Re: Need 0.013487 but I have 1.3487e-02
fprintf (pFile, "%i %i %f\n",i,j,matrizo[i][j])
-
August 24th, 2005, 11:56 PM
#3
Re: Need 0.013487 but I have 1.3487e-02
 Originally Posted by Hacker2
fprintf (pFile, "%i %i %f\n",i,j,matrizo[i][j])
Hacker2 tks for your answer ^^
But I really need the shorter version, with %f I'll have "0" after the number, thats why I'm using %g.
-
August 25th, 2005, 12:11 AM
#4
Re: Need 0.013487 but I have 1.3487e-02
You can specify the number of decimal place to be displayed.
Code:
fprintf (pFile, "%i %i %0.6f\n",i,j,matrizo[i][j]);
-
August 25th, 2005, 06:12 PM
#5
Re: Need 0.013487 but I have 1.3487e-02
Here is a complete spec of all the ways you can specify formatting
http://www.cplusplus.com/ref/cstdio/printf.html
-
August 26th, 2005, 12:25 AM
#6
Re: Need 0.013487 but I have 1.3487e-02
 Originally Posted by Kheun
You can specify the number of decimal place to be displayed.
Code:
fprintf (pFile, "%i %i %0.6f\n",i,j,matrizo[i][j]);
Kheun, I really need the numbers without "0", the way you told me will have sometimes unecessary "0" after:
Ex.:
0.500000
0.256000
...
But tks very much for your answer
-
August 26th, 2005, 12:28 AM
#7
Re: Need 0.013487 but I have 1.3487e-02
 Originally Posted by Hacker2
Tks very much 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
-
August 26th, 2005, 07:24 AM
#8
Re: Need 0.013487 but I have 1.3487e-02
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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|