Question : rounding decimal number in C
Answered by : grieving-gecko-8mvnc5rkt6d2
#include <stdio.h>
#include <math.h> int main()
{
float i=5.4, j=5.6;
printf("round of %f is %f\n", i, round(i));
printf("round of %f is %f\n", j, round(j));
return 0;
}
Source : https://fresh2refresh.com/c-programming/c-arithmetic-functions/c-round-function/ | Last Update : Fri, 06 Aug 21
Question : round decimal point in C
Answered by : phillyyy
#include <math.h>
float val = 37.777779;
float rounded_down = floorf(val * 100) / 100; /* Result: 37.77 */
float nearest = roundf(val * 100) / 100; /* Result: 37.78 */
float rounded_up = ceilf(val * 100) / 100; /* Result: 37.78 */
Source : https://stackoverflow.com/questions/1343890/how-do-i-restrict-a-float-value-to-only-two-places-after-the-decimal-point-in-c | Last Update : Wed, 05 Oct 22