How to concatenate two floats into a string in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    float f1 = 13.5;
    float f2 = 898.72;
    char buf[32] = "";

    snprintf(buf, 32, "%.2f %.2f", f1, f2);
    printf("%s\n", buf);

    return 0;
}




/*
run

13.50 898.72

*/

 



answered May 3, 2021 by avibootz
edited May 3, 2021 by avibootz

Related questions

1 answer 137 views
1 answer 161 views
1 answer 225 views
1 answer 155 views
3 answers 220 views
220 views asked Jun 13, 2017 by avibootz
1 answer 125 views
...