# Thread: float/int numbers understanding.....

1. ## float/int numbers understanding.....

im trying to write a temp conv. program from fahr to cel. by using a function , it works but im trying to make it print a number after the decimal and it gets all messed up...
Code:
```#include <stdio.h>

#define NEXTSTEP 20

int convertingfunction(int, int);

int main(void)
{
int c;
int i;

for(c = 0; c <= 300; c = c + 20)
printf("%d %3d\n", c, convertingfunction(c,i));
return 0;
}
int convertingfunction(int whzzup, int hehehe)
{
int d;
int c;
d = 0;

d = (5.0/9.0) * (whzzup-32);
return d;
}```
this works all right but how do u get it to print numbers after the decimal? i tried changing d into a float as well as c but they all come out messed up.

2. Try changing more than just d to a float, like perhaps the return value.

3. Even your printf is displaying and integer.

4. no i meant i tried turning everything into float, the printf % things and the variables like c, i, and d.

5. Originally Posted by i_can_do_this
no i meant i tried turning everything into float, the printf % things and the variables like c, i, and d.
funny. if I do that I get this output
Code:
```0.000000 -17.777779
20.000000 -6.666667
40.000000 4.444445
60.000000 15.555555
80.000000 26.666666
100.000000 37.777779
120.000000 48.888889
140.000000 60.000000
160.000000 71.111115
180.000000 82.222221
200.000000 93.333336
220.000000 104.444443
240.000000 115.555557
260.000000 126.666664
280.000000 137.777771
300.000000 148.888885```
Kurt

6. this works all right but how do u get it to print numbers after the decimal? i tried changing d into a float as well as c but they all come out messed up.
is this what u wanted. for instance take some floating point number
37.777779
u want to get the 37 separate and the .777779 separate, if i understand u well. to do that...

Code:
```#include<stdio.h>

int main()
{
double num=37.777779;
int beforedecimal;
double afterdecimal;

beforedecimal = (int) num;
afterdecimal = num - beforedecimal;

printf("Number before the decimal point ->> %d\n",beforedecimal);
printf("Number after the decimal point ->> %f\n",afterdecimal);

getchar();

return 0;
}
/*My ouptut
Number before the decimal point ->> 37
Number after the decimal point ->> 0.777779
*/```
hope this is what u wanted

ssharish2005

7. sorry but i realized that simply turning all the variables to floats wasnt enough, i need it to turn the function return type and parameters to floats too.... and ssharish nope thats not what i was looking for.

8. ssharish2005, there is a function called modf() in <math.h> that does what your code does.

Popular pages Recent additions