How to display a float to 2 decimal places in C

2 Answers

0 votes
#include <stdio.h>

int main(int argc, char **argv) 
{ 
    float f = 0.314;
    
    printf("%.2f", f);
    
    return(0);
}


/*
run:

0.31

*/

 



answered Jun 3, 2015 by avibootz
0 votes
#include <stdio.h>

int main(int argc, char **argv) 
{ 
    float f = 0.3554;
    
    printf("%.2f", f);
    
    return(0);
}


/*
run:

0.36

*/

 



answered Jun 3, 2015 by avibootz

Related questions

4 answers 651 views
4 answers 584 views
4 answers 755 views
2 answers 539 views
1 answer 221 views
1 answer 349 views
1 answer 306 views
...