Skip to content

Commit 4650c2c

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 2bfe164 commit 4650c2c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

hardware/arduino/sam/cores/arduino/WString.cpp

Lines changed: 7 additions & 2 deletions
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+
}

hardware/arduino/sam/cores/arduino/WString.h

Lines changed: 1 addition & 0 deletions
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)