title: How to specify number of digits to output for real numbers in Jansson
body: <p>How can I specify a fixed number of digits to output after the decimal point when using Jansson's json_dumps or json_dumpf() to output real numbers?</p>
  
  <p>I tried Jansson's new JSON_REAL_PRECISION flag, but that specifies the maximum number of significant digits, not a fixed number of digits after the decimal point.</p>
  
  <p>Basically I'm looking for something in Jansson that behaves like the following call to printf in C (with expected output of 123.12346):</p>
  
  <pre><code>printf("%.5f", 123.123456789);
  </code></pre>
  
  <p>[EDIT]</p>
  
  <p>Here's some sample code to illustrate the output styles I've tried so far (requires Jansson 2.7+):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;jansson.h&gt;
  
  int main(int argc, char* argv[])
  {
    json_t *json = json_object();
  
    json_object_set_new(json, "foo", json_real(123.123456789));
    printf("Output of json_dumps() for 123.123456789: %s\n", json_dumps(json, 0));
    printf("Again, but using JSON_REAL_PRECISION(5) : %s\n", json_dumps(json, JSON_REAL_PRECISION(5)));
  
    return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>Output of json_dumps() for 123.123456789: {"foo": 123.123456789}
  Again, but using JSON_REAL_PRECISION(5) : {"foo": 123.12}
  </code></pre>
  
  <p>Again, I need a way to output a fixed number of digits after the decimal (e.g. <strong>123.12346</strong>), anyone know how to achieve this?.</p>