Question: Basically I have a struct with a few float variables for hold inches data for different things. And I want convert this data to a string for print out.

I want convert for example this float value `"1.50"` to this `"1 f 0.5 inches"` for use in a `print("%s %s", convertToText(node -> data1), convertToText(node -> data2))` or something like that. But I am a bit confused to how implement this in c. So each `"%s"` needs be `"1 f 0.5 in"` but with his data converted.

Answer: 
You could find out the integer, and then calculate the mod of the value.

```
float input;
float decimal;
int integer;

scanf("%f", &input);

decimal = input%;
integer = input - decimal;
printf("%i f %f inches", integer, decimal);

```
To cope with proper rounding, etc. multiply by 12 first, then by the required precision and then segment the number.

---

This avoids `7.99999` --> `7 f 12.0 inch`, instead we get `8 f 0.0 inch`

When the number is negative, do not repeat the sign in the "inch" field.

Work over entire range of `float` which exceeds `int`.

```
#include <math.h>

int printf_feet_inches_tenths(float distance) {
  double d = round(distance * 12.0 * 10); // convert to exact 1/10 of inch
  double inch_tenths = fmod(d, 12 * 10);
  double feet = (d - inch_tenths) / (12 * 10);
  return printf("%.0f f %.1f inch\n", feet, fabs(inch_tenths) / 10);
}

void printf_feet_inches_tenths_test(void) {
  printf_feet_inches_tenths(7.5);
  printf_feet_inches_tenths(7.999);
  printf_feet_inches_tenths(-1.5);
  printf_feet_inches_tenths(1e30);
}

```

Output

```
7 f 6.0 inch
8 f 0.0 inch
-1 f 6.0 inch
1000000015047466219876688855040 f 0.0 inch

```