์ˆซ์ž๊ด€๋ จ๋ฉ”์†Œ๋“œ๐Ÿ’ก


๐ŸงกtoFixed()

  • ์†Œ์ˆ˜์ ์˜ n ๋ฒˆ์งธ ์ž๋ฆฌ๊นŒ์ง€๋งŒ ๋‚จ๊ธฐ๊ณ  ๋‚˜๋จธ์ง€ ์†Œ์ˆ˜์  ๋ฒ„๋ฆผ
  • toFixed(n)
  • ์ˆซ์žํƒ€์ž…์„ ์ธ์ˆ˜๋กœ ๋ฐ›์ง€๋งŒ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค
  const pi = 3.14159265358979
  
  pi.toFixed(2); //"3.14"

๐ŸงกparseInt()

  • ๋ฌธ์ž์—ด์˜ ์ˆซ์ž๋ฅผ ์ˆซ์žํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜
  • ์†Œ์ˆ˜์ ์„ ๋ฒ„๋ฆฌ๊ณ  ์ •์ˆ˜๋กœ ๋ฐ˜ํ™˜
  const pi = "3.14";

  parseInt(pi) // 3

๐ŸงกparseFloat()

  • ๋ฌธ์ž์—ด์˜ ์ˆซ์ž๋ฅผ ์ˆซ์žํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜
  • ์†Œ์ˆ˜์ ์„ ๋ณด์กดํ•ด์คŒ
  const pi = "3.14";

  parseFloat(pi) // 3.14

๐ŸงกtoLocaleString()

  • ์ˆซ์ž๋ฅผ ํ˜„์ง€ ์–ธ์–ด ํ˜•์‹์˜ ๋ฌธ์ž๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค
  • ๊ธˆ์•ก๋‹จ์œ„์— ์‰ผํ‘œ ๋ถ™๋Š”๊ฑฐ๋ž‘ ๋น„์Šท
  const num = 10000000
  
  console.log(num.toLocaleString()) //10,000,000

๐ŸงกNumber.isInteger()

  • ์ˆซ์ž๊ฐ€ ์ •์ˆ˜(Integer)์ธ์ง€ ํ™•์ธ
  const num = 123;
  const pi = 3.14;

  console.log(Number.inInteger(num)) //true
  console.log(Number.inInteger(pi)) //false

๐ŸงกMath

๐Ÿ’›Math.abs()

  • abs = absolute
  • ํŠน์ •ํ•œ ์ˆซ์ž์˜ ์ ˆ๋Œ“๊ฐ’์„ ๋ฐ˜ํ™˜ ( -1 => 1 )
  console.log(Math.abs(-12)) //12
  console.log(Math.abs(12)) //12

๐Ÿ’›Math.pow()

  • ์ฃผ์–ด์ง„ ์ˆซ์ž์˜ ๊ฑฐ๋“ญ์ œ๊ณฑํ•œ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  console.log(Math.pow(4, 2)) // 16
  console.log(Math.pow(7, 2)) // 49
  console.log(Math.pow(10, 3)) // 1000

๐Ÿ’›Math.min()

  • ์ธ์ˆ˜๋กœ ๋“ค์–ด์˜จ ์ˆซ์ž๋ฐ์ดํ„ฐ ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์„ ๋ฐ˜ํ™˜
  console.log(Math.min(1,2,3,4)) //1
  console.log(Math.min(34,12,10,72)) //10

๐Ÿ’›Math.max()

  • ์ธ์ˆ˜๋กœ ๋“ค์–ด์˜จ ์ˆซ์ž๋ฐ์ดํ„ฐ ์ค‘ ๊ฐ€์žฅ ํฐ ๊ฐ’์„ ๋ฐ˜ํ™˜
console.log(Math.max(1,2,3,4)) //4
console.log(Math.max(12,31,43,16)) //43

๐Ÿ’›Math.ceil()

  • ์˜ฌ๋ฆผ ์†Œ์ˆซ์ ์„ ์˜ฌ๋ฆฐ ์ •์ˆ˜ ๋ฐ˜ํ™˜
  console.log(Math.ceil(1.23)) //2
  console.log(Math.ceil(3.14)) //4

๐Ÿ’›Math.floor()

  • ๋‚ด๋ฆผ. ์†Œ์ˆซ์ ์„ ๋‚ด๋ฆฐ ์ •์ˆ˜ ๋ฐ˜ํ™˜
  console.log(Math.ceil(1.23)) //1
  console.log(Math.ceil(3.14)) //3

๐Ÿ’›Math.round()

  • ๋ฐ˜์˜ฌ๋ฆผ. ์†Œ์ˆซ์ ์„ ๋ฐ˜์˜ฌ๋ฆผํ•œ ์ •์ˆ˜ ๋ฐ˜ํ™˜
  console.log(Math.round(3.1)) //3
  console.log(Math.round(3.5)) //4

๐Ÿ’›Math.random()

  • ๋žœ๋คํ•œ 0~1 ์‚ฌ์ด์˜ ๋‚œ์ˆ˜ ๋ฐ˜ํ™˜ (1๊ณผ0์€ ์ ˆ๋Œ€ ๋‚˜์˜ค์ง€ ์•Š์Œ)
  console.log(Math.random()) //0.nnnnnnnnn (๋žœ๋ค)
  console.log(Math.random() * 10) //n.nnnnn (๋žœ๋ค)
  console.log(Math.floor(Math.random() * 10)) //n (๋žœ๋ค ์ •์ˆ˜)

  // ํŠน์ • ๋ฒ”์œ„์˜ ๋ฌด์ž‘์œ„ ์ •์ˆ˜๋ฅผ ์–ป๋Š” ํ•จ์ˆ˜
  // 0~9 ์‚ฌ์ด ์ •์ˆ˜
  function random(min = 0, max = 10) {
    return Math.floor(Math.random() * (max - min)) + min
  }
profile
ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์ผ๊ธฐ ๐Ÿ’ญ

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