Convert float decimal to Octal number in Python

Share on facebook
Share on twitter
Share on pinterest

In this Python program, we will have a look at “How to convert float decimal to octal number in python?”.

Python doesn’t support any inbuilt method to convert the same. Therefore, we need to do it manually.

Python Program to Convert float decimal to Octal number

 def float_bin(number, places = 3): 
 whole, dec = str(number).split(".") 
 whole = int(whole) 
 dec = int (dec) 
 res = bin(whole).lstrip("0b") + "."
 for x in range(places): 
 whole, dec = str((dec_converter(dec)) * 2).split(".") 
 dec = int(dec) 
 res += whole 
 return res 
 def dec_converter(num): 
 while num > 1: 
 num /= 10
 return num 
 n = input("Please enter floating point value : \n") 
 p = int(input("Please enter the number of decimal places : \n")) 
 print(float_bin(n, places = p)) 

Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *