Recent posts

Recent comments

Archive

Calender

«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

최종 수정일 : 2016. 3. 17.



Number() parseFloat()
  
<script type="text/javascript">
var a = Number( "10.00" ); 
var b = Number( "10.02" ); 

var c = Number( "12  34  56" ); 
var d = Number( "   40   " ); 

var e = Number( "50 years" ); 
var f = Number( "He was 60" ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo1" ).innerHTML = str; 
</script>
<script type="text/javascript">
var a = parseFloat( "10.00" ); 
var b = parseFloat( "10.02" ); 

var c = parseFloat( "12  34  56" ); 
var d = parseFloat( "   40   " ); 

var e = parseFloat( "50 years" ); 
var f = parseFloat( "He was 60" ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo2" ).innerHTML = str; 
</script>


Number() parseFloat()
  
<script type="text/javascript">
var a = Number( "034" ); 
var b = Number( 034 ); 

var c = Number( "0x34" ); 
var d = Number( 0x34 ); 

var e = Number( "3e4" ); 
var f = Number( 3e4 ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo3" ).innerHTML = str; 
</script>
<script type="text/javascript">
var a = parseFloat( "034" ); 
var b = parseFloat( 034 ); 

var c = parseFloat( "0x34" ); 
var d = parseFloat( 0x34 ); 

var e = parseFloat( "3e4" ); 
var f = parseFloat( 3e4 ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo4" ).innerHTML = str; 
</script>


Number() parseFloat()
  
<script type="text/javascript">
var a = Number( true ); 
var b = Number( false ); 

var c = Number( null ); 
var d = Number( undefined ); 

var e = Number( "" ); 
var f = Number( new Date()  ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo5" ).innerHTML = str; 
</script>
<script type="text/javascript">
var a = parseFloat( true ); 
var b = parseFloat( false ); 

var c = parseFloat( null ); 
var d = parseFloat( undefined ); 

var e = parseFloat( "" ); 
var f = parseFloat( new Date()  ); 


var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />" + 
"c = " + c + "<br />"+ 
"d = " + d + "<br />" + 
"e = " + e + "<br />" + 
"f = " + f + "<br />"; 

document.getElementById( "demo6" ).innerHTML = str; 
</script>


 
<script type="text/javascript">

var a = Number( "00.0001" ); 

var b = parseFloat( "00.0001" ); 

var str = "<br />" + 
"a = " + a + "<br />" + 
"b = " + b + "<br />"; 

document.getElementById( "demo7" ).innerHTML = str; 
</script>

참고로,
아래와 같이 작성한 경우에는, 오류가 나온다.

var a = Number( 00.0001 );
var b = parseFloat( 00.0001 );





이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요. *^^*