90 likes | 278 Views
Three Rounding Functions. Rounding up: ceil() Rounding down: floor() Rounding wrt 0.5: round(). Rounding functions. Rounding floats to integer *w.r.t = with respect to. +. ceil(). Rounds towards +infinity. -. floor(). Rounds towards -infinity. Example 1. Civil Eng.
E N D
Three Rounding Functions Rounding up: ceil() Rounding down: floor() Rounding wrt 0.5: round()
Rounding functions • Rounding floats to integer • *w.r.t = with respect to + ceil() Rounds towards +infinity - floor() Rounds towards -infinity
Example 1 Civil Eng. Stairs need to be built. Each 80lbs bag of concrete mix allows for coverage of 0.6 sq.ft. over a 2 inch thickness (so 0.1ft^3) How many bags are needed to build the stairs? Givens needed height, width, depth, number of steps Find Quantity of bags needed Theory height (ft) depth (ft) width (ft) (round up)
Example 1 Civil Eng. Assuming 4 stairs: 3ft wide, 7in tall, 11in deep totVolumeft3 = Nb_stairs * width * height * depth = 4 * 3 * 7/12 * 11/12 = 6.42 ft3 Number of bags = totVolumeft3/ volume1bag = 6.42/ 0.1 = 64.166 bags It's so close to 64, but we need to buy 65 bags.
Test your understanding • In one of the EGR101 (Intro To Engineering) projects, you must determine how many engines to put on the rocket. • Known values are: • total thrust required, and • thrust per one engine Nb of engines = total thrust required / thrust per one engine Which rounding function will be used to conclude? • floor( ) • ceil( ) • round( ) • No rounding is needed
Common Mistake • round(), ceil(), and floor() are functions that require 1 argument but also return a value. • You must collect or use the return value immediately!
Example 3 Hrs/Min/Sec Given a whole amount of seconds, convert to a format hr:min:sec. Example: ?
Suppose an ID number: 13948532 Isolate the last 4 digits! Try it yourself!
Key Points • New functions • round() • ceil() • floor() • Examples • Cement mix for stairs & rocket: ceil() • Time formatting: floor() • Id number: floor() • Remember to COLLECT the return value. Calling the function alone will NOT change the original value!