-
[JavaScript] 소수점 올림, 버림, 반올림Web Programming/JavaScript 2021. 1. 18. 11:53
소수점 올림
console.log(Math.ceil(7.004)); // expected output: 8
출처
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
Math.ceil() - JavaScript | MDN
The Math.ceil() function always rounds a number up to the next largest integer. Note: Math.ceil(null) returns integer 0 and does not give a NaN error. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to
developer.mozilla.org
소수점 버림
console.log(Math.floor(5.05)); // expected output: 5
출처
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
Math.floor() - JavaScript | MDN
The Math.floor() function returns the largest integer less than or equal to a given number. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://gith
developer.mozilla.org
소수점 반올림
console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05)); // expected output: 6 6 5
출처
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
Math.round() - JavaScript | MDN
The Math.round() function returns the value of a number rounded to the nearest integer. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.c
developer.mozilla.org
'Web Programming > JavaScript' 카테고리의 다른 글
[JavaScript] Object 반복문 사용하기 (for...in)/Key-Value 지정 (0) 2021.01.20