<p>I am trying to populate a string with a double value using a <code>sprintf</code> like this:</p>

<pre><code>sprintf(S, "%f", val);
</code></pre>

<p>But the precision is being cut off to six decimal places. I need about 10 decimal places for the precision.</p>

<p>How can that be achieved?</p>

[{'answer_id': 69747, 'author': 'Yann Ramin', 'author_id': 9167, 'author_profile': 'https://Stackoverflow.com/users/9167', 'pm_score': 3, 'selected': False, 'text': '<p>What you want is a modifier:</p>\n\n<pre><code>sprintf(S, "%.10f", val);\n</code></pre>\n\n<p>man sprintf will have many more details on format specifiers. </p>\n'}, {'answer_id': 69758, 'author': 'Agnel Kurian', 'author_id': 45603, 'author_profile': 'https://Stackoverflow.com/users/45603', 'pm_score': 4, 'selected': True, 'text': '<p>%[width].[precision]</p>\n\n<p>Width should include the decimal point.</p>\n\n<p>%8.2 means 8 characters wide; 5 digits before the point and 2 after. One character is reserved for the point.</p>\n\n<p>5 + 1 + 2 = 8</p>\n'}, {'answer_id': 69771, 'author': 'Jegschemesch', 'author_id': 1586, 'author_profile': 'https://Stackoverflow.com/users/1586', 'pm_score': 1, 'selected': False, 'text': '<p>For a more complete reference, see the <a href="http://en.wikipedia.org/wiki/Printf#printf_format_placeholders" rel="nofollow noreferrer">Wikipedia <em>printf</em> article, section "printf format placeholders"</a> and <a href="http://en.wikipedia.org/wiki/Printf#1970s:_C.2C_Lisp" rel="nofollow noreferrer">a good example on the same page</a>.</p>\n'}, {'answer_id': 69775, 'author': 'dajobe', 'author_id': 11177, 'author_profile': 'https://Stackoverflow.com/users/11177', 'pm_score': 1, 'selected': False, 'text': '<p>Take care - the output of sprintf will vary via C locale.  This may or may not be what you want.  See LC_NUMERIC in the locale docs/man pages.</p>\n'}, {'answer_id': 75791, 'author': 'EvilTeach', 'author_id': 7734, 'author_profile': 'https://Stackoverflow.com/users/7734', 'pm_score': 1, 'selected': False, 'text': '<p><code>%f</code> is for float values.</p>\n\n<p>Try using <code>%lf</code> instead. It is designed for doubles (which used to be called long floats).</p>\n\n<p><strong>double x = 3.14159265</strong>; <br/>\n<strong>printf("15.10lf\\n", x);</strong></p>\n'}]
['https://Stackoverflow.com/questions/69743', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11212/']