user41638: I'm using a Mega2560 and a generic SSD1306 OLED display with the Adafruit_SSD1306 (and by extension, Adafruit_gfx) library.
I need to print a bunch of float values (ranging between 30.0 and 99.9) to the display with exactly one decimal place of precision. The catch is, the Adafruit library doesn't have a printf() method, only one that takes a single ready-to-print string. 
Here's an (obviously non-Arduino) Java-like example of what I'm trying to accomplish:
String foo = String.format("%.1f, %.1f\%", temp1, hum1);
// "display" is my instance of Adafruit_SSD1306
display.print(foo);

So... how can I do something similar in Arduino-compatible C(++)?
Note: for this specific program, I have (relatively speaking) RAM to burn, so I really don't care if whatever library I use to generate formatted Strings is particularly efficient (as long as it isn't leaking). If it wants to use 4k of RAM and 80k of flash to format a 20-character String, so be it. 

user7508: The Adafruit_GFX class has two methods named print() and
println(). These behave exactly like Serial.print() and
Serial.println(). Specifically, when printing a float, you can provide
a second argument telling it the number of decimal places you want after
the decimal point:
display.print(temp1, 1);  // 1 digit after the decimal point
display.print(", ");
display.print(hum1, 1);  // ditto
display.print("%");

Background: the reason these methods behave like the ones of
Serial is that both Adafruit_GFX and HardwareSerial inherit them
from the Print virtual class.

user4143: Normally for formatting strings I'd suggest the venerable snprintf and similar functions. However, on an 8-bit Arduino when you're using floats that's not an option: the function that does all the formatting for this family if functions has had floating point support surgically removed from it. This is to make the function a fraction of the size so it's not as bloaty in small microcontrollers.
I believe there is a float-capable version somewhere on the internet that could be somehow installed, though I have never looked into doing that.
Instead you need to do the formatting of floats manually.  Everything else can be done with snprintf, but the floats need to be done separately.
Fortunately there's a function specifically for formatting a float into a character array (C-string), called dtostrf and is used thus:
float myVal = 23.49173783;
char *buffer[10]; // Enough room for the digits you want and more to be safe
dtostrf(myVal, 9, 1, buffer);

The first number in the parameter list is how many characters you want to have in your output, including the . and any leading -. Any extra characters are padded with space.  The second number is how many decimal places.  If the first number is negative the value is left-aligned. If it's positive it's right-aligned.  So the code above would give you:
〿〿〿〿〿23.5␀

(Note: I am using 〿 to denote a space character.) If you used -9 you'd get:
23.5〿〿〿〿〿␀

You can, of course, feed that created string into another string using snprintf and the %s placeholder.  
char buf2[32];
snprintf(buf2, 32, "The temperature is: %s\r\n", buffer);

buf2 ⇒ "The temperature is: 23.5〿〿〿〿〿"

If you want to trim the string down to just contain the number portion and lose the spaces it's best to left-align it with a negative width, then change the first space to a ␀:
char *space = strchr(buffer, ' ');
if (space != NULL) {
    *space = '\0';
}


41638: <p>I'm using a Mega2560 and a generic SSD1306 OLED display with the Adafruit_SSD1306 (and by extension, Adafruit_gfx) library.</p>

<p>I need to print a bunch of float values (ranging between 30.0 and 99.9) to the display with exactly one decimal place of precision. The catch is, the Adafruit library doesn't have a printf() method, only one that takes a single ready-to-print string. </p>

<p>Here's an (obviously non-Arduino) Java-like example of what I'm trying to accomplish:</p>

<pre><code>String foo = String.format("%.1f, %.1f\%", temp1, hum1);
// "display" is my instance of Adafruit_SSD1306
display.print(foo);
</code></pre>

<p>So... how can I do something similar in Arduino-compatible C(++)?</p>

<p>Note: for this specific program, I have (relatively speaking) RAM to burn, so I really don't care if whatever library I use to generate formatted Strings is particularly efficient (as long as it isn't leaking). If it wants to use 4k of RAM and 80k of flash to format a 20-character String, so be it. </p>
 7508: <p>The <code>Adafruit_GFX</code> class has two methods named <code>print()</code> and
<code>println()</code>. These behave exactly like <code>Serial.print()</code> and
<code>Serial.println()</code>. Specifically, when printing a float, you can provide
a second argument telling it the number of decimal places you want after
the decimal point:</p>

<pre><code>display.print(temp1, 1);  // 1 digit after the decimal point
display.print(", ");
display.print(hum1, 1);  // ditto
display.print("%");
</code></pre>

<p><strong>Background</strong>: the reason these methods behave like the ones of
<code>Serial</code> is that both <code>Adafruit_GFX</code> and <code>HardwareSerial</code> inherit them
from the <a href="https://github.com/arduino/Arduino/blob/1.8.5/hardware/arduino/avr/cores/arduino/Print.h" rel="nofollow noreferrer"><code>Print</code> virtual class</a>.</p>
 4143: <p>Normally for formatting strings I'd suggest the venerable <code>snprintf</code> and similar functions. However, on an 8-bit Arduino when you're using floats that's not an option: the function that does all the formatting for this family if functions has had floating point support surgically removed from it. This is to make the function a fraction of the size so it's not as bloaty in small microcontrollers.</p>

<p>I believe there is a float-capable version somewhere on the internet that could be somehow installed, though I have never looked into doing that.</p>

<p>Instead you need to do the formatting of floats manually.  Everything else can be done with <code>snprintf</code>, but the floats need to be done separately.</p>

<p>Fortunately there's a function specifically for formatting a float into a character array (C-string), called <code>dtostrf</code> and is used thus:</p>

<pre><code>float myVal = 23.49173783;
char *buffer[10]; // Enough room for the digits you want and more to be safe
dtostrf(myVal, 9, 1, buffer);
</code></pre>

<p>The first number in the parameter list is how many characters you want to have in your output, including the <code>.</code> and any leading <code>-</code>. Any extra characters are padded with space.  The second number is how many decimal places.  If the first number is negative the value is left-aligned. If it's positive it's right-aligned.  So the code above would give you:</p>

<pre><code>〿〿〿〿〿23.5␀
</code></pre>

<p>(Note: I am using <code>〿</code> to denote a space character.) If you used <code>-9</code> you'd get:</p>

<pre><code>23.5〿〿〿〿〿␀
</code></pre>

<p>You can, of course, feed that created string into another string using <code>snprintf</code> and the <code>%s</code> placeholder.  </p>

<pre><code>char buf2[32];
snprintf(buf2, 32, "The temperature is: %s\r\n", buffer);

buf2 ⇒ "The temperature is: 23.5〿〿〿〿〿"
</code></pre>

<p>If you want to trim the string down to just contain the number portion and lose the spaces it's best to left-align it with a negative width, then change the first space to a <code>␀</code>:</p>

<pre><code>char *space = strchr(buffer, ' ');
if (space != NULL) {
    *space = '\0';
}
</code></pre>
