Numbers Flashcards
let billion = 1e9; //
1 billion, literally: 1 and 9 zeroes
let mсs = 0.000001;
another way of writing this
let mсs =
1e-6;
round number down
math.floor
round number up
math.ceil
Rounds to the nearest integer
math.round
The method ________rounds the number to n digits after the point and returns a string representation of the result.
toFixed(n)
let sum = 0.1 + 0.2;
alert( sum ); // returns
.300000000004
the most reliable method is to round the result with the help of a method
toFixed(n):
let sum = 0.1 + 0.2;
alert( sum.toFixed(2) ); // “0.30”
returns a string. How can you return an interger?
alert( +sum.toFixed(2) );
add plus sign.
alert( +”100px” ); // returns and why?
NaN
Numeric conversion using a plus + or Number() is strict.
They “read” a number from a string until they can’t. In case of an error, the gathered number is returned.
parseInt and parseFloat
alert( parseFloat(‘12.5em’) ); // 12.5
hey “read” a number from a string until they can’t. In case of an error, the gathered number is returned. The function parseInt returns an integer, whilst parseFloat will return a floating-point number:
alert( parseInt(‘a123’) ); //
NaN, the first symbol stops the process
Returns a random number from 0 to 1 (not including 1).
math.random()
Returns the greatest and smallest from the arbitrary number of arguments.
Math.max(a, b, c…) and Math.min(a, b, c…)