From 3b9db65ea33890e9fa5e911ea4170e4b31fd03be Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 14 Apr 2019 15:33:15 -0700 Subject: [PATCH] Add String::toDouble from upstream Arduino core (#5986) Fixes #5985 --- cores/esp8266/WString.cpp | 11 +++++++++-- cores/esp8266/WString.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index d949e2904..69444696a 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -829,17 +829,24 @@ void String::trim(void) { // /*********************************************/ long String::toInt(void) const { - if(buffer()) + if (buffer()) return atol(buffer()); return 0; } float String::toFloat(void) const { - if(buffer()) + if (buffer()) return atof(buffer()); return 0; } +double String::toDouble(void) const +{ + if (buffer()) + return atof(buffer()); + return 0.0; +} + // global empty string to allow returning const String& with nothing const String emptyString; diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index aecf9b4a6..11b12aa08 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -241,6 +241,7 @@ class String { // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; protected: // Contains the string info when we're not in SSO mode