hi all
output isCode:#include <stdio.h> main() { float i,j=100.0,k=19456.0; i=j/k; printf(******** %f \n",i); }
******** 0.005139803
i would like round figure it like
0.005.
how can i do this
greetings munna
This is a discussion on float value within the C Programming forums, part of the General Programming Boards category; hi all Code: #include <stdio.h> main() { float i,j=100.0,k=19456.0; i=j/k; printf(******** %f \n",i); } output is ******** 0.005139803 i would ...
hi all
output isCode:#include <stdio.h> main() { float i,j=100.0,k=19456.0; i=j/k; printf(******** %f \n",i); }
******** 0.005139803
i would like round figure it like
0.005.
how can i do this
greetings munna
You can control the precision by trying something like : "%.af" where 'a' is the number of digits following the decimal point.
In the middle of difficulty, lies opportunity
also you should learn to use int main()
and properly indent your code
If I have eight hours for cutting wood, I spend six sharpening my axe.
Looking at your code, I am guessing you must be using a compiler like TC or BC. Please switch over th GCC. It will help you in the long run.
In the middle of difficulty, lies opportunity
Ofcourse it does,
Code:# include<stdio.h> int main() { float i,j=100.0,k=19456.0; i=j/k; printf("******** %.3f \n",i); printf("******** %.5f \n",i); return 0; }
my output:
Code:******** 0.005 ******** 0.00514
In the middle of difficulty, lies opportunity