-
Notifications
You must be signed in to change notification settings - Fork 3
/
number.js
46 lines (35 loc) · 1.34 KB
/
number.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// make control on number
let num = 10
let num2 = 15.8
let strNum = '15'
// ## => 1 convert string to number (float number)
// let convert = parseInt(strNum); // num will be 123
// ## => 1 convert string to number (float number)
let convert = parseFloat("123.45"); // num will be 123.45
console.log(convert);
// conver any str num to num
let numberMethod = Number("123"); // num will be 123
console.log(numberMethod);
// return true from the string 😂😂
let d7k = isNaN("hello"); // returns true
console.log(d7k);
// Reverse the negative signal
let reverse = Math.abs(-500); // returns 5
console.log(reverse);
// let roundMethod = Math.round(4.5); // returns 5
let roundMethod = Math.round(4.4); // returns 4
console.log(roundMethod);
// remove the decimal number
let floorMethod = Math.floor(num2); // returns 15
console.log(floorMethod);
//
let ceilMethod = Math.ceil(4.1); // returns 5
console.log(ceilMethod);
let randomNum = Math.random(1, 100); // randomNum will be a random value between 0 (inclusive) and 1 (exclusive)
console.log(randomNum);
let rundomNumber = (max) => Math.floor(Math.random() * max)
console.log(`randomNum: ${+rundomNumber(100)}`)
// get max number of arrays
let arr = [1, 20, 30, 40, 50, 60, 70, 80, 110]
console.log(`max number of arrays: '${Math.max(...arr)}'`);
console.log(`min number of arrays: '${Math.min(...arr)}'`);