How do I create a string so that it formats floating point numbers to have no trailing decimal point or digits when it is an integer, but to NOT switch to scientific notation for larger numbers?
When I do:
float myFloat= 15.6f; float myInt = 5.0f; float myLarge = 7000000.0f; sprintf(out, "my float is %g", myFloat); sprintf(out, "my int is %g", myInt); sprintf(out, "my large is %g", myLarge);
I get something like:
my float is 15.6 my int is 5 my large is 7e+07f
I want all a single format string that will give 15.6, 5, and 700000.
Edited cause comments don't do formatting:
that's what I thought. but a wrapper is pretty inconvenient though as the format strings are embedded in longer format strings:
sprintf(buf, "%d %g", myInt, myFloat);
how do you wrap that?
sprintf(buf, "%d %g", myInt, Wrapper(myFloat));??
what should Wrapper return? Or worse:
sprintf(buf, "%d %s", myInt, Wrapper(myFloat));??