How to convert float to string with 2 decimal places in C

1 Answer

0 votes
#include <stdio.h>

int main(void) {

    float f = 782305.8731;

    char s[16] = "";

    sprintf(s, "%.2f", f);

    puts(s);


}



/*
run:

782305.88

*/

 



answered Feb 12, 2023 by avibootz

Related questions

1 answer 261 views
2 answers 379 views
1 answer 133 views
1 answer 206 views
2 answers 237 views
2 answers 206 views
...