[๐ŸŒณJavascript] ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด -Number

h-a-n-aยท2023๋…„ 1์›” 11์ผ
1

๐ŸŒณjavascript

๋ชฉ๋ก ๋ณด๊ธฐ
3/17

.toFixed() : ์ˆซ์ž๋ฅผ .toFixed(์ž๋ฆฟ์ˆ˜)๊นŒ์ง€ ๋ฌธ์ž๋กœ ๋ฐ˜ํ™˜ํ•ด ํ‘œํ˜„

const num = 3.1415926
console.log(num.toFixed(2)) // '3.14' 
'์ฐธ๊ณ ' parseFloat('3.14') // 3.14 (๋ฌธ์ž์—ด์„ ์‹ค์ˆ˜๋กœ ๋ฐ”๊ฟˆ)

.toLocaleString() : ์ˆซ์ž๋ฅผ ํ˜„์ง€ ์–ธ์–ดํ˜•์‹์˜ ๋ฌธ์ž๋กœ ๋ฐ˜ํ™˜

const num = 1000000000000000
num.toLocaleString()// '1,000,000,000,000,000'

Number.isInteger() : ์ˆซ์ž๊ฐ€ ์ •์ˆ˜์ธ์ง€ ํ™•์ธ

const num = 123
const pi =3.14
console.log(Number.isIntegar(num)) // true
console.log(Number.isInegar(pi)) // false

Number.isNaN() : ์ฃผ์–ด์ง„ ๊ฐ’์ด NaN์ธ์ง€ ํ™•์ธ

const num1 = NaN
const num2 = false
const num3 = 12
console.log(num1) //true
console.log(num2) // false
console.log(num3) //false

Number.parseInt() : ์ฃผ์–ด์ง„ ๊ฐ’(์ˆซ์ž,๋ฌธ์ž)์„ ํŒŒ์‹ฑํ•ด ํŠน์ • ์ง„์ˆ˜์˜ ์ •์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 10์ง„์ˆ˜์ž„์„ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•  ๊ฒƒ!

const str = '3.145'
console.log(Number.parseInt(str, 10)) //3

Number.parseFloat() : ์ฃผ์–ด์ง„ ๊ฐ’(์ˆซ์ž,๋ฌธ์ž)๋ฅผ ํŒŒ์‹ฑํ•ด ๋ถ€๋™์†Œ์ˆ˜์  ์‹ค์ˆ˜๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

const str = '3.14'
console.log(Number.parseFloat(str))// 3.14
profile
ํ•˜๋ฃจํ•˜๋ฃจ๊ฐ€ ์—ฐ์Šต์ด๋‹ˆ ๋‚ด์ผ์€ ๋” ๊ฐ•ํ•ด์งˆ ๊ฒ๋‹ˆ๋‹ค

0๊ฐœ์˜ ๋Œ“๊ธ€