//toFixed(2) 인수로 소수점 몇번째까지 고정할지 정함, 단 type이 string으로 변환됨
const pi = 3.141592535
console.log(pi);
const str = pi.toFixed(2);
console.log(str);//3.14
console.log(typeof str); //string
//숫자와 관련된 대표적인 전역함수parseInt, parseFloat
const integer = parseInt(str);
const float = parseFloat(str);
console.log(integer,float); //3 3.14
console.log(typeof integer, typeof float);//number number
//내장객체 Math
//Math.abs(-x) //x //절대갇ㅄ
//Math min(a,b) //최소값, max도 동일
//Math.ceil(소수점) //올림 floor은 내림 round는 반올림
//Math.random //랜덤숫자
console.log(Math.floor(Math.random()*10)); //random한 숫자 구할때 많이 쓰는 유형
'프론트엔드 공부 > javscript' 카테고리의 다른 글
정규식표현 + .find(),.findIndex,includes() (0) | 2021.05.25 |
---|---|
map과 forEach 차이 (0) | 2021.05.25 |
String prototype - indexOf,length,slice,replace,match,trim (0) | 2021.05.21 |
class 상속과 확장 (0) | 2021.05.21 |
일반함수와 화살표함수에서 this 정의 차이점 (0) | 2021.05.21 |