The Timely Measurements Assignment asks you to round your output to a certain number of decimals. There are many ways to round using javascript, here I'll discuss one way by hacking the Math.round() method.
Math.round()
- rounds to the nearest integer (if the decimal is 0.5 or greater it rounds up, otherwise it rounds down.)Math.ceil()
- rounds up to the next integer.Math.floor()
- rounds down.Let's do some examples:
var x = 2.71828182845;
Math.round(x);
Math.ceil(x);
Math.floor(x);