How to you print floats with printf
Posted:
Sun Nov 29, 2020 9:00 pm
by doe_head
Hello,
When trying to print floating point numbers I get no output. Also, when trying so sprintf a float no conversion takes place. Is there a floating point library and if there is how do I enable it?
Thanks!
Re: How to you print floats with printf
Posted:
Mon Dec 14, 2020 5:46 pm
by davydnorris
There's no float formats compiled into the SDK to keep it small. Simplest way is to use something like this - set the define to the maximum places your range will allow, and set the format string to the number you want to print:
Code: Select all#define DEC_PLACE_MULTIPLIER 10000
char * print_float_voltage(double d_voltage) {
int32_t voltage = d_voltage * DEC_PLACE_MULTIPLIER;
os_sprintf(buf, "V = %d.%04u", voltage / DEC_PLACE_MULTIPLIER, abs(voltage) % DEC_PLACE_MULTIPLIER);
return buf;
}
Re: How to you print floats with printf
Posted:
Mon Jan 31, 2022 9:18 pm
by st0ff3r
you can use tinyprintf with floating point support - its two files
https://github.com/st0ff3r/tinyprintf
Re: How to you print floats with printf
Posted:
Tue Feb 01, 2022 11:36 am
by rpiloverbd