1 / 9

Three Rounding Functions

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.

sovann
Download Presentation

Three Rounding Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Three Rounding Functions Rounding up: ceil() Rounding down: floor() Rounding wrt 0.5: round()

  2. Rounding functions • Rounding floats to integer • *w.r.t = with respect to + ceil() Rounds towards +infinity - floor() Rounds towards -infinity

  3. 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)

  4. 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.

  5. 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

  6. 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!

  7. Example 3 Hrs/Min/Sec Given a whole amount of seconds, convert to a format hr:min:sec. Example: ?

  8. Suppose an ID number: 13948532  Isolate the last 4 digits! Try it yourself!

  9. 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!

More Related