Skip to content

Commit 2c26660

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 e6f81fd commit 2c26660

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

hardware/arduino/avr/cores/arduino/WString.cpp

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

741741
float String::toFloat(void) const
742742
{
743-
if (buffer) return float(atof(buffer));
744-
return 0;
743+
return float(toDouble());
745744
}
745+
746+
double String::toDouble(void) const
747+
{
748+
if (buffer) return atof(buffer);
749+
return 0;
750+
}

hardware/arduino/avr/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)