29μž₯ Math

29.1 Math ν”„λ‘œνΌν‹°

29.1.1 Math.PI

Math.PI // 3.14159265...

μ›μ£Όμœ¨ 값을 λ°˜ν™˜ν•œλ‹€.


29.2 Math λ©”μ„œλ“œ

29.2.1 Math.abs

Math.abs(-1) // 1
Math.abs('-1') // 1
Math.abs('') // 0
Math.abs(1) // 1
Math.abs('string') // NaN

μ „λ‹¬λœ 숫자의 μ ˆλŒ€κ°’μ„ λ°˜ν™˜ν•œλ‹€. μˆ«μžλŠ” λ°˜λ“œμ‹œ 0 λ˜λŠ” μ–‘μˆ˜, μˆ«μžκ°€ μ•„λ‹ˆλ©΄ NaN 을 λ°˜ν™˜ν•œλ‹€.

29.2.2 Math.round

Math.round(1.4) // 1
Math.round(1.6) // 2
Math.round(-1.4) // -1
Math.round(-1.6) // -2
Math.round(1) // 1
Math.round() // NaN

μ „λ‹¬λœ 숫자의 μ†Œμˆ˜μ  μ΄ν•˜λ₯Ό λ°˜μ˜¬λ¦Όν•œ μ •μˆ˜λ₯Ό λ°˜ν™˜ν•œλ‹€. μˆ«μžκ°€ μ•„λ‹ˆλ©΄ NaN 을 λ°˜ν™˜ν•œλ‹€.

29.2.3 Math.ceil

μ „λ‹¬λœ 숫자의 μ†Œμˆ˜μ  μ΄ν•˜λ₯Ό μ˜¬λ¦Όν•œ μ •μˆ˜λ₯Ό λ°˜ν™˜ν•œλ‹€. μˆ«μžκ°€ μ•„λ‹ˆλ©΄ NaN 을 λ°˜ν™˜ν•œλ‹€.

29.2.4 Math.floor

μ „λ‹¬λœ 숫자의 μ†Œμˆ˜μ  μ΄ν•˜λ₯Ό λ‚΄λ¦Όν•œ μ •μˆ˜λ₯Ό λ°˜ν™˜ν•œλ‹€. μˆ«μžκ°€ μ•„λ‹ˆλ©΄ NaN 을 λ°˜ν™˜ν•œλ‹€.

29.2.5 Math.sqrt

μ „λ‹¬λœ 숫자의 μ œκ³±κ·Όμ„ λ°˜ν™˜ν•œλ‹€.

29.2.6 Math.random

μž„μ˜μ˜ λ‚œμˆ˜(랜덀 숫자)λ₯Ό λ°˜ν™˜ν•œλ‹€. λ°˜ν™˜ν•˜λŠ” λ‚œμˆ˜λŠ” 0μ—μ„œ 1 미만의 μ‹€μˆ˜μ΄λ‹€.

29.2.7 Math.pow

첫 번째 인수λ₯Ό λ°‘, 두 번째 인수λ₯Ό μ§€μˆ˜λ‘œ κ±°λ“­μ œκ³±ν•œ κ²°κ³Όλ₯Ό λ°˜ν™˜ν•œλ‹€.

ES7 μ—μ„œ λ„μž…λœ μ§€μˆ˜ μ—°μ‚°μžκ°€ 가독성이 더 μ’‹λ‹€.

29.2.8 Math.max

전달받은 수 쀑 κ°€μž₯ 큰 수λ₯Ό λ°˜ν™˜ν•œλ‹€.

배열을 전달받아 λ°°μ—΄ μš”μ†Œ 쀑 μ΅œλŒ€κ°’μ„ κ΅¬ν•˜λ €λ©΄

29.2.9 Math.min

전달받은 수 쀑 κ°€μž₯ μž‘μ€ 수λ₯Ό λ°˜ν™˜ν•œλ‹€.

배열을 전달받아 λ°°μ—΄ μš”μ†Œ 쀑 μ΅œμ†Œκ°’μ„ κ΅¬ν•˜λ €λ©΄

Last updated

Was this helpful?