I'm writing C code that outputs a double into a string to be part of a JSON string.
What C print format directive should I use to output the double?
As far as I know, a valid JSON number must never start with '.'. It must start with "0." Instead. The exponent and fractional part are not output when all 0.
The printed number must have the maximum precision, but also do smart rounding so that the double 0.3 is printed as 0.3. This is tricky to handle when the input number is 0.3 for instance.