Using floats with sprintf() in embedded C

后端 未结 13 1845
别跟我提以往
别跟我提以往 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:07

    Yes of course, there is nothing special with floats. You can use the format strings as you use in printf() for floats and anyother datatypes.

    EDIT I tried this sample code:

    float x = 0.61;
    char buf[10];
    sprintf(buf, "Test=%.2f", x);
    printf(buf);
    

    Output was : Test=0.61

提交回复
热议问题