const balance = new Number("500")
console.log(balance+500);
console.log(balance.toString().length);
console.log(balance.toFixed(1));
Console Output:
1000
3
500.0
const otherNumber = 123.8966
console.log(otherNumber.toPrecision(4));
Console Output:
123.9
const hundreds = 1000000
console.log(hundreds.toLocaleString('en-IN'));
Console Output:
10,00,000
Maths
console.log(Math);
console.log(Math.abs(-4));
console.log(Math.round(4.6));
console.log(Math.ceil(4.2));
console.log(Math.floor(4.9));
console.log(Math.min(4, 3, 6, 8));
console.log(Math.max(4, 3, 6, 8));
Console Output:
Object [Math] {}
4
5
5
4
3
8
console.log(Math.random());
console.log((Math.random()*10) + 1);
console.log(Math.floor(Math.random()*10) + 1);
Console Output:
0.1952364441147425
6.256284058932861
6
Generating random number between two numbers
const min = 10
const max = 20
console.log(Math.floor(Math.random() * (max - min + 1)) + min)
Console Output:
15