Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,621 questions

10,674 answers

573 users

How to round floating point number to the closest integer which is less than a given value in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>
 
int main()
{
    double x = 4.311, y = 6.500, z = 9.811;
    
    printf("%.3f\n", floor(x));
    printf("%.3f\n", floor(y));
    printf("%.3f\n", floor(z));
 
    x = -4.311, y = -6.500, z = -9.811;
    
    printf("%.3f\n", floor(x));
    printf("%.3f\n", floor(y));
    printf("%.3f\n", floor(z));
 
    return 0;
}

/*
run:

4.000
6.000
9.000
-5.000
-7.000
-10.000

*/

 




answered May 17 by avibootz
...