예전에 소수점 처리 때문에 꽤나 애먹었던 기억이 있다.
이리저리 검색도 해보고, 도움말도 보고....
<script language= "JavaScript">
// strValue : 처리하려는 값
// strType : '* 소수점 계산. 0:절사, 1:반올림, 2:올림
function fnFixNum( strValue, strType)
{
var iType = parseInt( strType );
switch ( type )
{
case 0 : // 절사
return( parseInt( strValue ) );
break;
case 1 : // 반올림
if( strValue< 0 ){ //음수일 경우
if( ( Math.abs( strValue ) + 0.5 )
- ( parseInt( Math.abs( strValue ) + 0.5 ) ) == 0 ){
return ( ( parseInt( Math.abs( strValue ) + 0.5 ) * -1 ) +1 );
}
else
{
return ( parseInt( Math.abs( strValue ) + 0.5 ) * -1 );
}
} else { //양수 일 경우
return ( parseInt( strValue + 0.5 ) )
}
break;
case 2 : //올림
if( ( value - parseInt( strValue ) ) >= 0.1 ) {
return ( parseInt( strValue ) +1 );
}
if( ( value - parseInt( strValue ) ) <= -0.1 ){
return ( parseInt( strValue ) -1 ) ;
}
}//End switch
}//End function
</script>