Approach. To convert a decimal number that has a fractional part to octal, first convert the integer part to octal, then the fractional part to octal, and finally combine the two results to get the final answer.
For the integer part, keep dividing the number by 8 and noting the remainder until the dividend is less than 8, and copy all the rest together.
For the decimal part, keep multiplying the decimal part by 8 until we get 0 as a fractional part. After multiplying for the first time, write down the integral part, then multiply the decimal part of the new value by 8 again and keep doing this until the perfect number is reached.
Above steps can be written as:
7 (base 10) = 7 (base 8) and .16 (base 10) = .1217 (base 8)
Now , to get the octal of the decimal number 7.16, merge the two octal results.
(7) 10 = (7) 8
(0.16) 10 = (0.1217 & # 8230;) 8
So, (7.16) 10 = (7.1217 & # 8230;) 8
or, (7.16) 10 = (7.1217) 8 (approx. value)
Below is the implementation:
Enter your floating point value: 7.16 Enter the number of decimal places of the result: 10 7.1217273146 strong>
Enter your floating point value: 7.1234 Enter the number of decimal places of the result: 5 7.07713