Math.floor() | parseInt() |
| |
<script type="text/javascript">
var a = Math.floor( "12.34" );
var b = Math.floor( "56.78" );
var c = Math.floor( "-12.34" );
var d = Math.floor( "-56.78" );
var e = Math.floor( "12 34 56" );
var f = Math.floor( " 40 " );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo1" ).innerHTML = str;
</script>
|
<script type="text/javascript">
var a = parseInt( "12.34" );
var b = parseInt( "56.78" );
var c = parseInt( "-12.34" );
var d = parseInt( "-56.78" );
var e = parseInt( "12 34 56" );
var f = parseInt( " 40 " );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo2" ).innerHTML = str;
</script>
|
Math.floor() | parseInt() |
| |
<script type="text/javascript">
var a = Math.floor( "034" );
var b = Math.floor( 034 );
var c = Math.floor( "0x34" );
var d = Math.floor( 0x34 );
var e = Math.floor( "3e4" );
var f = Math.floor( 3e4 );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo3" ).innerHTML = str;
</script>
|
<script type="text/javascript">
var a = parseInt( "034" );
var b = parseInt( 034 );
var c = parseInt( "0x34" );
var d = parseInt( 0x34 );
var e = parseInt( "3e4" );
var f = parseInt( 3e4 );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo4" ).innerHTML = str;
</script>
|
Math.floor() | parseInt() |
| |
<script type="text/javascript">
var a = Math.floor( true );
var b = Math.floor( false );
var c = Math.floor( null );
var d = Math.floor( undefined );
var e = Math.floor( "" );
var f = Math.floor( new Date() );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo5" ).innerHTML = str;
</script>
|
<script type="text/javascript">
var a = parseInt( true );
var b = parseInt( false );
var c = parseInt( null );
var d = parseInt( undefined );
var e = parseInt( "" );
var f = parseInt( new Date() );
var str = +
+ a + +
+ b + +
+ c + +
+ d + +
+ e + +
+ f + ;
document.getElementById( "demo6" ).innerHTML = str;
</script>
|
|
<script type="text/javascript">
var a = Math.floor( "00.0001" );
var b = parseInt( "00.0001" );
var str = +
+ a + +
+ b + ;
document.getElementById( "demo7" ).innerHTML = str;
</script>
|
참고로,
아래와 같이 작성한 경우에는, 오류가 나온다.
var a = Math.floor( 00.0001 );
var b = parseInt( 00.0001 );
이 내용이 도움이 되셨다면, 아래의 하트 버튼을 눌러주세요. *^^*