# Thread: Round conversion to 2 decimal places

1. ## Round conversion to 2 decimal places

I'm attempting to convert feet into metres by multiplying the feet (int data type) by 0.3048 since 1 foot is 0.3048 in metres.

After doing so in my function that returns a double data type, I'm attempting to print the new value using the printf command and that command is like so:

Code:
```altMetres = convert_feet_to_metres(altitude);

printf("\n\tTime: %ds, Altitude: %.2dm, Position: %f'N %f'E", timeStamp, altMetres, decDegreeLat, decDegreeLon);```
My Conversion function:

Code:
```double convert_feet_to_metres(int feet)
{
/* one foot is 0.3048 in metres */
return (feet * 0.3048);
}```
When the value stored in altitude is 3566, the above code prints the following after my function is invoked, something weird is happening, why is Altitude -845249564 and not 1086.9168. I'm using the %.2d (format specifier) in a poor attempt to get the value (when correct calculation is done) to output 1086.92 since I need two decimal places, I ain't got this far since the calculation is all wrong.

Time: 1106059583s, Altitude: -845249564m, Position: 0.000000'N -0.000000'E
If anyone can give us a hint, would be most appreciated.

2. probably your format is not suitable to the variable type - check it or show the var definitions

3. fixed it, I changed &#37;.2dm to %.2fm. I throught the d (format specifier) was for when specifying a double since the variable the conversion is stored in is a double data type. %f being for floats.

4. Originally Posted by Cero.Uno
fixed it, I changed %.2dm to %.2fm. I throught the d (format specifier) was for when specifying a double since the variable the conversion is stored in is a double data type. %f being for floats.
Such things should not be guessed - read the manual for printf/scanf formats. And note that they are not fully equivalent

5. Originally Posted by Cero.Uno
fixed it, I changed %.2dm to %.2fm. I throught the d (format specifier) was for when specifying a double since the variable the conversion is stored in is a double data type. %f being for floats.
Floats are implicitly cast to double, when passed to printf, so they have the same format specifier. Much like chars and shorts are cast to int.

You really should check a reference for these kinds of things.