1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

WString: add toDouble

`toFloat` internally converts into double and then truncates into a
float, so why not add a method to return the double?
This commit is contained in:
Iván Pérez 2016-09-12 08:56:02 +02:00
parent 2bfe164b9a
commit 4650c2c3d8
4 changed files with 16 additions and 4 deletions

View File

@ -740,6 +740,11 @@ long String::toInt(void) const
float String::toFloat(void) const
{
if (buffer) return float(atof(buffer));
return 0;
return float(toDouble());
}
double String::toDouble(void) const
{
if (buffer) return atof(buffer);
return 0;
}

View File

@ -190,6 +190,7 @@ public:
// parsing/conversion
long toInt(void) const;
float toFloat(void) const;
double toDouble(void) const;
protected:
char *buffer; // the actual char array

View File

@ -742,6 +742,11 @@ long String::toInt(void) const
float String::toFloat(void) const
{
if (buffer) return float(atof(buffer));
return 0;
return float(toDouble());
}
double String::toDouble(void) const
{
if (buffer) return atof(buffer);
return 0;
}

View File

@ -190,6 +190,7 @@ public:
// parsing/conversion
long toInt(void) const;
float toFloat(void) const;
double toDouble(void) const;
protected:
char *buffer; // the actual char array