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 445 views
4 answers 416 views
4 answers 554 views
2 answers 408 views
1 answer 141 views
1 answer 261 views
1 answer 207 views
...