최종 수정일 : 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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
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 = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo6" ).innerHTML = str;
</script>
|
|
<script type="text/javascript">
var a = Number( "00.0001" );
var b = parseFloat( "00.0001" );
var str = +
+ a + +
+ b + ;
document.getElementById( "demo7" ).innerHTML = str;
</script>
|
참고로,
아래와 같이 작성한 경우에는, 오류가 나온다.
var a = Number( 00.0001 );
var b = parseFloat( 00.0001 );
이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요. *^^*