Hi,
Can somebody advise what the best method is to round a float value UP to the nearest whole value:
i.e 1.678 should result in 2.000
i.e 1.012 should also result in 2.000
i.e 1.001 should result in 1.000
Thanks,
Manny
Hi,
Can somebody advise what the best method is to round a float value UP to the nearest whole value:
i.e 1.678 should result in 2.000
i.e 1.012 should also result in 2.000
i.e 1.001 should result in 1.000
Thanks,
Manny
ceil in math.h does what you want:
http://www.cplusplus.com/reference/c...math/ceil.html
osuee
ceil normally would do the job, but it will not for turning 1.001 into 1.000, because that is not rounded up, that is either rounded off or rounded down. Perhaps that was a typo.
Try this on for size:
Code:float num; float rounded_num; printf("Enter the number you want rounded: "); scanf("%f", &num); rounded_num = (int)(num + .5f); printf("%f rounded to the nearest whole value is %f\n", num, rounded_num);
Don't quote me on that... ...seriously