Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 템플릿 문자열
- overflow: hidden
- placeholder
- 프로그래머스
- display와 visibility
- HTML5문서
- opacity
- flex box
- Til
- 외계행성의 나이
- 오블완
- CSS 스타일
- 스코프
- GIT
- history API
- CSS Object Model
- 티스토리챌린지
- 시맨틱
- Code States
- Scope
- HTML요소
- github
- section태그와 article태그의 차이점
- javascript
- BOM
- 깃허브
- CSS 박스모델
- block 박스
- 객체지향프로그래밍
- 코드스테이츠
Archives
- Today
- Total
해말그미의 코딩공부
TIL : Math 관련함수 본문
function solution(price) {
if(price >= 500000){
return Math.floor(price - (price * 0.2))
} if(price >= 300000){
return Math.floor(price -(price * 0.1))
}if(price >= 100000){
return Math.floor(price -(price * 0.05))
} else{return price}
}
주의하지 못한 점
1. 할인된 금액을 return하는 것이 아니라 "지불해야 하는 금액"이라는 것.'
2. 소수점 이하를 버린 정수를 return한다는 것.
Math.floor(price * 0.2)
처음에는 이런식으로 할인된 금액을 적어서 틀렸다.
그리고 제한사항을 제대로 보지않아 Math.floor을 쓰지 않았다.
복습
Math.floor() 함수는 주어진 숫자와 같거나 작은 정수 중에서 가장 큰 수를 반환합니다
(즉, 소수점 뒤에를 버리는데 그 숫자보다 작은 값중 가장 큰 정수를 반환 / 소수점 이하를 버림)
console.log(Math.floor(5.95)); // Expected output: 5 console.log(Math.floor(5.05)); // Expected output: 5 console.log(Math.floor(5)); // Expected output: 5 console.log(Math.floor(-5.05)); // Expected output: -6 |
Math.ceil() 은 소수점 이하를 올림
Math.ceil(0.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8 Math.ceil(-0.95); // -0 Math.ceil(-4); // -4 Math.ceil(-7.004); // -7 |
Math.round()은 소수점 이하를 반올림한다.
console.log(Math.round(0.9)); // Expected output: 1 console.log(Math.round(5.95), Math.round(5.5), Math.round(5.05)); // Expected output: 6 6 5 console.log(Math.round(-5.05), Math.round(-5.5), Math.round(-5.95)); // Expected output: -5 -5 -6 |
이 3개 먼가 조금씩 헷갈린단 말이지...; ㅠㅠ
Comments