Help rounding-off numbers (not using printf)

Lloyd Kremer kremer at cs.odu.edu
Tue May 23 00:31:37 AEST 1989



In article <2730 at oregon.uoregon.edu> michelbi at oregon.uoregon.edu (Michel Biedermann) writes:

>Is there a C function (user defined or primitive (?)) that will let me
>truncate or round-off a number UP TO a certain decimal place.

I believe the function "ceil" is the most mathematically rigorous choice.
It rounds up (toward positive infinity) to the nearest integer equal to or
greater than the given number.

	extern double ceil(double);

	/* Round up to one decimal precision */
	double num, result;

	result = ceil(10.0 * num) / 10.0;

-- 
					Lloyd Kremer
					Brooks Financial Systems
					...!uunet!xanth!brooks!lloyd
					Have terminal...will hack!



More information about the Comp.lang.c mailing list