Place Value of a given digit in a number | Function to find place value ; Digit , which we want to find place value . ; Number from where we want to find place value .
function placeValue ( N , num ) { var total = 1 , value = 0 , rem = 0 ; while ( true ) { rem = N % 10 ; N = parseInt ( N / 10 ) ; if ( rem == num ) { value = total * rem ; break ; } total = total * 10 ; } return value ; } var D = 5 ; var N = 85932 ; document . write ( placeValue ( N , D ) ) ;