From the course: C Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Rounding and truncating

Rounding and truncating - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

Rounding and truncating

- [Instructor] Let's see some nearest integer functions in the C standard library. First we have round, which returns the closest integer value to the argument. The trunc function returns the truncated value. That is, the function returns the integer part of the argument. Next we have the ceiling and floor functions. Ceiling returns the smallest integer value not less than the argument. This may be used to calculate the hours to bill in a parking lot that only charges per hour. So if you stayed for 5.2 hours, you will be billed for six hours anyway. Finally, the floor function returns the largest integer value not greater than the argument. This is what people use to report the age of a person. For example, if someone is 23.7 years old, people just say 23.

Contents