Using floats with sprintf() in embedded C

后端 未结 13 1779
别跟我提以往
别跟我提以往 2020-12-24 06:35

Guys, I want to know if float variables can be used in sprintf() function.

Like, if we write:

sprintf(str,\"adc_read = %d \         


        
相关标签:
13条回答
  • 2020-12-24 07:13

    %g can do this:

    #include <stdio.h>
    int main() {
      float w = 234.567;
      char x[__SIZEOF_FLOAT__];
      sprintf(x, "%g", w);
      puts(x);
    }
    
    0 讨论(0)
提交回复
热议问题