Skip to content

Commit e792ba2

Browse files
bigdinotechcalvinatintel
authored andcommitted
Fix bug when using StringConstructor with doubles
-Fixes issue of StringContructor instability with doubles
1 parent acc4b38 commit e792ba2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: cores/arduino/WString.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ String::String(float value, unsigned char decimalPlaces)
136136
int len = digitsBe4Decimal(value);
137137
init();
138138

139-
if(decimalPlaces) len = 1 + ((int)decimalPlaces & 0x0FF);
139+
if(decimalPlaces) len += 1 + ((int)decimalPlaces & 0x0FF);
140140

141141
char buf[len+1];
142142
*this = dtostrf(value, 0, decimalPlaces, buf);
@@ -147,7 +147,7 @@ String::String(double value, unsigned char decimalPlaces)
147147
int len = digitsBe4Decimal(value);
148148
init();
149149

150-
if(decimalPlaces) len = 1 + ((int)decimalPlaces & 0x0FF);
150+
if(decimalPlaces) len += 1 + ((int)decimalPlaces & 0x0FF);
151151

152152
char buf[len+1];
153153
*this = dtostrf(value, 0, decimalPlaces, buf);

0 commit comments

Comments
 (0)