And %f is hard-coded to be five digit precision. Would you consider a patch which uses this variable for floating conversion precision?
Code: Select all
Index: chprintf.c
===================================================================
--- chprintf.c (revision 6773)
+++ chprintf.c (working copy)
@@ -73,10 +73,12 @@
}
#if CHPRINTF_USE_FLOAT
-static char *ftoa(char *p, double num) {
+static char *ftoa(char *p, double num, unsigned long precision) {
long l;
- unsigned long precision = FLOAT_PRECISION;
+ if (precision == 0)
+ precision = FLOAT_PRECISION;
+
l = (long)num;
p = long_to_string_with_divisor(p, l, 10, 0);
*p++ = '.';
@@ -211,7 +213,7 @@
*p++ = '-';
f = -f;
}
- p = ftoa(p, f);
+ p = ftoa(p, f, precision);
break;
#endif
case 'X':
With this patch code like
Code: Select all
chprintf(chp, "d %f\r\n", 0.12345678);
chprintf(chp, "0 %..1f\r\n", 0.12345678);
chprintf(chp, "3 %..1000f\r\n", 0.12345678);
chprintf(chp, "6 %..1000000f\r\n", 0.12345678);
outputs
Code: Select all
d 0.12345
0 0.0
3 0.123
6 0.123456
(yes, with two dots between % and f)