human
Convert decimal fraction to binary number | Function to convert decimal to binary upto k - precision after decimal point.
Fetch the integral part of decimal number.
Fetch the fractional part decimal number.
Conversion of integral part to binary equivalent.
Append 0 in binary.
Reverse string to get original binary equivalent.
Append point before conversion of fractional part.
Conversion of fractional part to binary equivalent.
Find next bit in fraction.
Driver code"
How can the above be solved in Python?

What is a code to convert decimal fraction to binary number and the other steps required?
assistant
#Here is code to convert decimal fraction to binary number and the other steps required.
 def decimalToBinary ( num , k_prec ) :
	binary = " "
	Integral = int ( num )
	fractional = num - Integral
	while ( Integral ) :
		rem = Integral % 2
		binary += str ( rem ) ;
		Integral //= 2
	binary = binary [ : : - 1 ]
	binary += ' . '
	while ( k_prec ) :
		fractional *= 2
		fract_bit = int ( fractional )
		if ( fract_bit == 1 ) :
			fractional -= fract_bit
			binary += '1'
		else :
			binary += '0'
		k_prec -= 1
	return binary
if __name__ == " _ _ main _ _ " :
	n = 4.47
	k = 3
	print ( decimalToBinary ( n , k ) )
	n = 6.986
	k = 5
	print ( decimalToBinary ( n , k ) )