JavaScript provides built-in mathematical functions like Math.max(), Math.min(), Math.round(), etc.
Example:
let number1 = 5.67, number2 = 12.34;
let max = Math.max(number1, number2); // Finds maximum
let min = Math.min(number1, number2); // Finds minimum
let round = Math.round(number1); // Rounds to nearest integer
let floor = Math.floor(number1); // Rounds down
let ceil = Math.ceil(number1); // Rounds up
console.log(max); // 12.34
console.log(min); // 5.67
console.log(round); // 6
console.log(floor); // 5
console.log(ceil); // 6
Explanation:
Math.max() returns the largest value.
Math.min() returns the smallest value.
Math.round(), Math.floor(), and Math.ceil() handle rounding of numbers.
No comments:
Post a Comment