Skip to content

ESP8266 currently doesn't support sprintf/snprintf floating point formatting #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Adafruit_IO_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ bool Adafruit_IO_Feed::send(float value) {
#if defined(ARDUINO_ARCH_AVR)
// Use avrlibc dtostre function on AVR platforms.
dtostre(value, _converted, 10, 0);
#elif defined(ESP8266)
String result = String(value, 2);
result.toCharArray(_converted, sizeof(_converted)-1);
#else
// Otherwise fall back to snprintf on other platforms.
snprintf(_converted, sizeof(_converted)-1, "%f", value);
Expand All @@ -170,6 +173,9 @@ bool Adafruit_IO_Feed::send(double value) {
#if defined(ARDUINO_ARCH_AVR)
// Use avrlibc dtostre function on AVR platforms.
dtostre(value, _converted, 10, 0);
#elif defined(ESP8266)
String result = String(value, 2);
result.toCharArray(_converted, sizeof(_converted)-1);
#else
// Otherwise fall back to snprintf on other platforms.
snprintf(_converted, sizeof(_converted)-1, "%f", value);
Expand Down