You can chat about native SDK questions and issues here.

User avatar
By doe_head
#89633 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!
User avatar
By davydnorris
#89799 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;
}