diff --git a/hardware/arduino/avr/cores/arduino/WString.cpp b/hardware/arduino/avr/cores/arduino/WString.cpp index 9975303c8e1..f2572d60883 100644 --- a/hardware/arduino/avr/cores/arduino/WString.cpp +++ b/hardware/arduino/avr/cores/arduino/WString.cpp @@ -740,6 +740,11 @@ long String::toInt(void) const float String::toFloat(void) const { - if (buffer) return float(atof(buffer)); + return float(toDouble()); +} + +double String::toDouble(void) const +{ + if (buffer) return atof(buffer); return 0; } diff --git a/hardware/arduino/avr/cores/arduino/WString.h b/hardware/arduino/avr/cores/arduino/WString.h index de5632c12c1..77709c3ba42 100644 --- a/hardware/arduino/avr/cores/arduino/WString.h +++ b/hardware/arduino/avr/cores/arduino/WString.h @@ -190,6 +190,7 @@ class String // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; protected: char *buffer; // the actual char array diff --git a/hardware/arduino/sam/cores/arduino/WString.cpp b/hardware/arduino/sam/cores/arduino/WString.cpp index 533298225e4..71bbc07d13b 100644 --- a/hardware/arduino/sam/cores/arduino/WString.cpp +++ b/hardware/arduino/sam/cores/arduino/WString.cpp @@ -742,6 +742,11 @@ long String::toInt(void) const float String::toFloat(void) const { - if (buffer) return float(atof(buffer)); + return float(toDouble()); +} + +double String::toDouble(void) const +{ + if (buffer) return atof(buffer); return 0; } diff --git a/hardware/arduino/sam/cores/arduino/WString.h b/hardware/arduino/sam/cores/arduino/WString.h index de5632c12c1..77709c3ba42 100644 --- a/hardware/arduino/sam/cores/arduino/WString.h +++ b/hardware/arduino/sam/cores/arduino/WString.h @@ -190,6 +190,7 @@ class String // parsing/conversion long toInt(void) const; float toFloat(void) const; + double toDouble(void) const; protected: char *buffer; // the actual char array