Skip to content

Commit ac625aa

Browse files
authored
Merge pull request #77 from brentru/add-prec
add prec. points to sending AVR and non-avr (SAMD/ESP32) targets
2 parents 88e837a + a5b90f6 commit ac625aa

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit IO Arduino
2-
version=2.7.22
2+
version=2.7.23
33
author=Adafruit
44
maintainer=Adafruit <adafruitio@adafruit.com>
55
sentence=Arduino library to access Adafruit IO.

src/AdafruitIO_Data.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ void AdafruitIO_Data::setValue(float value, double lat, double lon, double ele,
182182

183183
#if defined(ARDUINO_ARCH_AVR)
184184
// Use avrlibc dtostre function on AVR platforms.
185-
dtostre(value, _value, 10, 0);
185+
dtostre(value, _value, precision, 0);
186186
#elif defined(ESP8266)
187187
// ESP8266 Arduino only implements dtostrf and not dtostre. Use dtostrf
188188
// but accept a hint as to how many decimals of precision are desired.
189189
dtostrf(value, 0, precision, _value);
190190
#else
191191
// Otherwise fall back to snprintf on other platforms.
192-
snprintf(_value, sizeof(_value)-1, "%f", value);
192+
snprintf(_value, sizeof(_value) - 1, "%0.*f", precision, value);
193193
#endif
194194

195195
setLocation(lat, lon, ele);
@@ -201,14 +201,14 @@ void AdafruitIO_Data::setValue(double value, double lat, double lon, double ele,
201201

202202
#if defined(ARDUINO_ARCH_AVR)
203203
// Use avrlibc dtostre function on AVR platforms.
204-
dtostre(value, _value, 10, 0);
204+
dtostre(value, _value, precision, 0);
205205
#elif defined(ESP8266)
206206
// ESP8266 Arduino only implements dtostrf and not dtostre. Use dtostrf
207207
// but accept a hint as to how many decimals of precision are desired.
208208
dtostrf(value, 0, precision, _value);
209209
#else
210210
// Otherwise fall back to snprintf on other platforms.
211-
snprintf(_value, sizeof(_value)-1, "%f", value);
211+
snprintf(_value, sizeof(_value) - 1, "%0.*f", precision, value);
212212
#endif
213213

214214
setLocation(lat, lon, ele);

0 commit comments

Comments
 (0)