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 349 views
2 answers 510 views
1 answer 233 views
1 answer 319 views
2 answers 376 views
2 answers 367 views
...