Skip to main content
Arduino

Return to Revisions

1 of 3

One can use the String() type initialization to convert any number, including float to String. For example to convert 3.14159 simply type ⤵︎

float num = 3.14159
String str1 = String(num, 1) // 3.1
String str2 = String(num, 2) // 3.14
String str3 = String(num, 3) // 3.141

To the right of the comma is the number of decimal places one wants the string result to have. It has a lot of functionality but that's one of the overloads. You can see them all here!

To see this code working on a .ino sketch check out this GitHub repo https://github.com/aeonSolutions/aeonlabs-ESP32-C-Base-Firmware-Libraries

AltStyle によって変換されたページ (->オリジナル) /