Skip to content

Commit 69a2a52

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? Signed-off-by: Iván Pérez <ivanperez2@gmail.com>
1 parent 740d316 commit 69a2a52

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

cores/arduino/WString.cpp

Lines changed: 6 additions & 1 deletion
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));
745+
return float(toDouble());
746+
}
747+
748+
double String::toDouble(void) const
749+
{
750+
if (buffer) return atof(buffer);
746751
return 0;
747752
}

cores/arduino/WString.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class String
186186
// parsing/conversion
187187
long toInt(void) const;
188188
float toFloat(void) const;
189+
double toDouble(void) const;
189190

190191
protected:
191192
char *buffer; // the actual char array

0 commit comments

Comments
 (0)