From 7ac22c149117b3abeb7be75af7801ef4d9f21ffa Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Wed, 14 Sep 2016 14:09:20 -0400 Subject: [PATCH] WString: add `toDouble` Port of https://github.com/arduino/Arduino/pull/5362 --- cores/arduino/WString.cpp | 9 +++++++-- cores/arduino/WString.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 73a96f9f..ff0bd8da 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -810,6 +810,11 @@ long String::toInt(void) const float String::toFloat(void) const { - if (buffer) return float(atof(buffer)); - return 0; + return (float)toDouble(); +} + +double String::toDouble(void) const +{ + if (buffer) return atof(buffer); + return 0; } diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h index 75a3e143..2ff259f8 100644 --- a/cores/arduino/WString.h +++ b/cores/arduino/WString.h @@ -199,6 +199,7 @@ class String // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; char * getCSpec(int base, bool issigned, bool islong); protected: