diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp index 4faf9bd9..e5c95534 100644 --- a/cores/arduino/Print.cpp +++ b/cores/arduino/Print.cpp @@ -286,23 +286,10 @@ size_t Print::printLongLong(unsigned long long n, uint8_t base) { } -size_t Print::printFloat(double number, uint16_t decimalPlaces) +size_t Print::printFloat(double number, uint8_t digits) { - if(decimalPlaces>16) - decimalPlaces = 16; - int digits = 0; - int intValue = (int)number; - while(intValue !=0) - { - intValue /= 10; - digits++; - } - digits += decimalPlaces; - if(number < 0) - digits++; - char str[digits]; - - - dtostrf(number, 0, digits-1, str); + char str[50]; + + dtostrf(number, 0, digits, str); return(print(str)); } diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index ed7bd7cc..16552079 100644 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -37,7 +37,7 @@ class Print int write_error; size_t printNumber(unsigned long, uint8_t); size_t printLongLong(unsigned long long, uint8_t); - size_t printFloat(double, uint16_t); + size_t printFloat(double, uint8_t); protected: void setWriteError(int err = 1) { write_error = err; } public: @@ -67,7 +67,7 @@ class Print size_t print(long long, int = DEC); size_t print(unsigned long, int = DEC); size_t print(unsigned long long, int = DEC); - size_t print(double, int = 2); + size_t print(double, int = BIN); size_t print(const Printable&); size_t println(const __FlashStringHelper *); @@ -81,7 +81,7 @@ class Print size_t println(long long, int = DEC); size_t println(unsigned long, int = DEC); size_t println(unsigned long long, int = DEC); - size_t println(double, int = 2); + size_t println(double, int = BIN); size_t println(const Printable&); size_t println(void); };