Using floats with sprintf() in embedded C

后端 未结 13 1881
别跟我提以往
别跟我提以往 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 
    int main() {
      float w = 234.567;
      char x[__SIZEOF_FLOAT__];
      sprintf(x, "%g", w);
      puts(x);
    }
    

提交回复
热议问题