Here is my solution:
#include <stdio.h> void printDouble(double fp); int main(void) { printDouble(11.0); printDouble(11.45); } void printDouble(double fp) { double _fp; char buffer[40]; int i = 0; do{ sprintf(buffer, "%.*lf", i, fp); sscanf(buffer, "%lf", &_fp); i++; } while(fp != _fp); puts(buffer); }
Output:
11 11.45
This may be somewhat inefficient, but it works . Anyway, you don't need to print floating point numbers often.
source share