Closed CptanPanic closed 6 years ago
Here is a function that should work.
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
if(isnan(number)) {
strcpy(s, "nan");
return s;
}
if(isinf(number)) {
strcpy(s, "inf");
return s;
}
if(number > 4294967040.0 || number < -4294967040.0) {
strcpy(s, "ovf");
return s;
}
char* out = s;
// Handle negative numbers
if(number < 0.0) {
*out = '-';
++out;
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for(uint8_t i = 0; i < prec; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long) number;
double remainder = number - (double) int_part;
out += sprintf(out, "%d", int_part);
// Print the decimal point, but only if there are digits beyond
if(prec > 0) {
*out = '.';
++out;
}
while(prec-- > 0) {
remainder *= 10.0;
if((int)remainder == 0){
*out = '0';
++out;
}
}
sprintf(out, "%d", (int) remainder);
return s;
}
Thank you! I will fix it soon.
Should be fixed now on master branch. Thanks.
Yes I verified it works. Thanks.
And in latest version 0.5.3 it is broken again :( reverting back to 0.5.2 fixed it
Thanks. Sorry will fix that asap
@Zuijdam Maybe you need to update your ESP8266 Arduino Core. What version do you use?
@Zuijdam the bug is confirmed, but it is a bug of ESP8266 Arduino Core. You should update to the latest ESP8266 Arduino Core to resolve this.
Thank for the update. I will check it and reply here.
I am having an issue with Blynk virtual write using TIVA 129 board and Energia. If I try to send a float the app display remains blank. I have to convert to an integer then it works. How can I send a float?
@johnddawson it means that specific board has a bug (on TI side).
Anyway, a simple workaround would be to enable BLYNK_USE_INTERNAL_DTOSTRF
.
You'll need to dig into the library a little bit, to figure it out.
To enable, do you just enter #define BLYNK_USE_INTERNAL_DTOSTRFin the sketch?
On Tuesday, October 2, 2018 1:11 PM, Volodymyr Shymanskyy <notifications@github.com> wrote:
@johnddawson it means that specific board has a bug (on TI side). Anyway, a simple workaround would be to enable BLYNK_USE_INTERNAL_DTOSTRF.— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@johnddawson no it won't work. You'll have to put it in BlynkConfig.h
BLYNK_USE_INTERNAL_DTOSTRF
is now enabled automatically for all TI boards (Energia IDE)
So I am using an esp8266 and trying to do a virtualWrite of a double/float, and all I get on blynk app is %.3f. I did some more investigating, and found that this is actually a problem with the printf not supporting %f. I am not sure this is just a esp8266 thing, or maybe even an arduino issue. I found this function http://pastebin.com/FdBFk3F4 that should just work instead of snprintf(). You can also see this issue reported at:
http://community.blynk.cc/t/how-to-send-float-number-to-android-app/761/4
https://github.com/esp8266/Arduino/issues/341