From our discussion in the above answer here is my program that works for any number of digits before the decimal.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    float f1 = 12.13;
    float f2 = 12.245;
    float f3 = 1242.145;
    float f4 = 1214.1;
    int i = 0;
    char *s1 = (char *)(malloc(sizeof(char) * 20));
    char *s2 = (char *)(malloc(sizeof(char) * 20));
    sprintf(s1, "%f", f1);
    s2 = strchr(s1, '.');
    i = s2 - s1;
    printf("%.*g\n", (i+2), f1);
    sprintf(s1, "%f", f2);
    s2 = strchr(s1, '.');
    i = s2 - s1;
    printf("%.*g\n", (i+2), f2);
    sprintf(s1, "%f", f3);
    s2 = strchr(s1, '.');
    i = s2 - s1;
    printf("%.*g\n", (i+2), f3);
    sprintf(s1, "%f", f4);
    s2 = strchr(s1, '.');
    i = s2 - s1;
    printf("%.*g\n", (i+2), f4);
    free(s1);
    free(s2);
    return 0;
}
And here's the output
12.13
12.24
1242.15
1214.1