Find the Nth digit in the proper fraction of two numbers | Function to print the Nth digit in the fraction ( p / q ) ; To store the resultant digit ; While N > 0 compute the Nth digit by dividing p and q and store the result into variable res and go to next digit ; Driver code
function findNthDigit ( p , q , N ) { var res ; while ( N > 0 ) { N -- ; p *= 10 ; res = parseInt ( p / q ) ; p %= q ; } return res ; } var p = 1 , q = 2 , N = 1 ; document . write ( findNthDigit ( p , q , N ) ) ;