👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
This article will show you how to use the math object to understand how a floating point number is rounded to the nearest whole number.
As a reminder, when rounding a number, we look to the right of the decimal point to understand whether we are rounding up or down. If it is 0.5 or more and positive, we round up; if it is less than 0.5 when it is positive, we round down. In case of negative numbers, the threshold is slightly modified: if 0.5 or less, we round down. Here is the syntax:
Since we are using the Math object, let’s start with the math. The round method comes next. The set of brackets calls the method on the input value inside the brackets and returns the rounded value.
If you were to insert a string or null in the entry, it returns NaN. Try the code editor above and enter floating point numbers to get a feel for how Math.round () method works.
There you go ! You can now use the Math object to figure out how to round a number. Here are some articles that may help you determine what to learn next:
👻 Read also: what is the best laptop for engineering students?
By the way, this material is also available in other languages:
Rome | 2023-02-09
Berlin | 2023-02-09
Paris | 2023-02-09