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 426 views
4 answers 399 views
4 answers 537 views
2 answers 394 views
1 answer 132 views
1 answer 253 views
1 answer 199 views
...