'ToString'에 해당되는 글 2건

  1. 2022.04.12 자바스크립트, 숫자, 수학 method (Number, Math)
  2. 2013.02.15 toString 정리 필요
반응형

1. toString() : 10 진수 -> 2진수/16진수

let num = 10;

num.toString();
num.toString(2);

let num2 = 100;

num2.toString(16);

------------------------------------------------------------

2. Math.ceil() : 올림

let num1 = 2.1;
let num2 = 2.5;

Math.ceil(num1);
Math.ceil(num2);

------------------------------------------------------------

3. Math.floor() : 내림

let num1 = 2.1;
let num2 = 2.5;

Math.floor(num1);
Math.floor(num2);

------------------------------------------------------------

4. Math.round() : 반올림

let num1 = 2.1;
let num2 = 2.5;

Math.round(num1);
Math.round(num2);

------------------------------------------------------------

5. 소숫점 자릿수
- 요구사항 : 소수점 둘째자리 까지 표현(셋째 자리에서 반올림)

let userRate = 10.12345;

Math.round(userRate * 100) / 100

------------------------------------------------------------

6. 소숫점 자릿수 : toFixed()
- 요구사항 : 소수점 둘째자리 까지 표현(셋째 자리에서 반올림)

let userRate = 10.12345;
userRate.toFixed(2);
userRate.toFixed(0);
userRate.toFixed(6);

let userRate = 10.12345;
userRate.toFixed(2);
Number(userRate.toFixed(2));

------------------------------------------------------------

7. isNaN()

let x = Number('x');

x == NaN;
x === NaN;
NaN == NaN;

isNaN(x);
isNaN(1);

------------------------------------------------------------

8. parseInt()

let margin = '10px';
parseInt(margin);
Number(margin);

let redColor = 'f3';
parseInt(redColor);
parseInt(redColor, 16);
parseInt('10', 2);

------------------------------------------------------------

9. parseFloat()

let padding = "10.5%";
parseInt(padding);
parseFloat(padding);

------------------------------------------------------------

10. Math.random() : 0 ~ 1 사이 무작위 숫자 생성

Math.random();
Math.random();
Math.random();

1 ~ 100 사이 임의의 숫자를 뽑고 싶다면?
Math.floor(Math.random()*100) + 1

------------------------------------------------------------

11. Math.max() / Math.min()

Math.max(1, 4, -2, 5, 11, 9, 6, 2.1);
Math.min(1, 4, -2, 5, 11, 9, 6, 2.1);


------------------------------------------------------------

12. Math.abs() : 절대값

Math.abs(-1)


------------------------------------------------------------

13. Math.pow(n, m) : 제곱

Math.pow(2, 10);


------------------------------------------------------------

14. Math.sqrt() : 제곱근

Math.sqrt(16);

반응형

toString 정리 필요

개발 및 관리/Java 2013. 2. 15. 11:50 posted by HighLighter
반응형

자바 toString 정리 필요함

 

http://blog.naver.com/ksj_7701?Redirect=Log&logNo=130130902034

 

http://blog.naver.com/javaking75?Redirect=Log&logNo=140157770558

 

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040201&docId=66599463&qb=7J6Q67CUIHRvU3RyaW5n&enc=utf8&section=kin&rank=1&search_sort=0&spq=0&pid=Re2QIc5Y7uNsssfyh6ssssssst4-292035&sid=UR2f6HJvLCcAAASyPQc

반응형