Skip to content

Commit 5d459d0

Browse files
committed
WString: add toDouble
`toFloat` internally converts into double and then truncates into a float, so why not add a method to return the double?
1 parent 4620f6c commit 5d459d0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cores/arduino/WString.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ long String::toInt(void) const
742742

743743
float String::toFloat(void) const
744744
{
745-
if (buffer) return float(atof(buffer));
746-
return 0;
745+
return float(toDouble());
747746
}
747+
748+
double String::toDouble(void) const
749+
{
750+
if (buffer) return atof(buffer);
751+
return 0;
752+
}

cores/arduino/WString.h

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class String
190190
// parsing/conversion
191191
long toInt(void) const;
192192
float toFloat(void) const;
193+
double toDouble(void) const;
193194

194195
protected:
195196
char *buffer; // the actual char array

0 commit comments

Comments
 (0)