Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,970 questions

51,912 answers

573 users

How to round a float to N decimals in C

3 Answers

0 votes
#include <stdio.h>

int main(void) {
    float number = 82.79521;

    printf("%.2f", number);

    return 0;
}




/*
run:

82.80

*/

 



answered Jul 29, 2022 by avibootz
0 votes
#include <stdio.h>

int main(void) {
    float number = 82.73521;

    printf("%.2f", number);

    return 0;
}




/*
run:

82.74

*/

 



answered Jul 29, 2022 by avibootz
0 votes
#include <stdio.h>

int main(void) {
    float number = 82.73165;

    printf("%.2f", number);

    return 0;
}




/*
run:

82.73

*/

 



answered Jul 29, 2022 by avibootz

Related questions

4 answers 171 views
171 views asked Jul 29, 2022 by avibootz
3 answers 156 views
1 answer 127 views
1 answer 229 views
1 answer 129 views
129 views asked Aug 7, 2019 by avibootz
1 answer 185 views
185 views asked Jan 17, 2019 by avibootz
...