# [JavaScript] Numbers, Dates, Intl and Timers - Math and Rounding

```
console.log(Math.sqrt(25)); // sqaureroot
console.log(25 ** (1 / 2));
console.log(8 ** (1 / 3));

console.log(Math.max(5, 18, 23, 11, 2));
console.log(Math.max(5, 18, '23', 11, 2));
console.log(Math.max(5, 18, '23px', 11, 2));

console.log(Math.min(5, 18, 23, 11, 2));

console.log(Math.PI * Number.parseFloat('10px') ** 2);

// getting dice random number
console.log(Math.trunc(Math.random() * 6) + 1);

// getting random number between min and max value.
const randomInt = (min, max) =>
  Math.floor(Math.random() * (max - min) + 1) + min; // better for negative number

// Math.trunc(Math.random() * (max - min) + 1) + min;
// 0...1 -> 0...(max - min) -> min...(max - min + min) -> min...max
console.log(randomInt(10, 20));

// Rounding integers
console.log(Math.round(23.3)); // rounding down
console.log(Math.round(23.9)); // rounding up

console.log(Math.ceil(23.3)); // rounding up
console.log(Math.ceil(23.9)); // rounding up

console.log(Math.floor(23.3)); // rounding down
console.log(Math.floor('23.9')); // rounding down

console.log(Math.trunc(-23.3)); // just throw decimal part
console.log(Math.floor(-23.3)); // accurate rounding

// Rounding decimals
console.log((2.7).toFixed(0)); // toFixed returns Strings, not Number
console.log((2.7).toFixed(3));
console.log((2.345).toFixed(2));
console.log((2.345).toFixed(2));
console.log(+(2.345).toFixed(2)); // returns Numbers
```


![math and rounding.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1657829227944/PoxSD4BlG.PNG align="left")


