How to convert octal to decimal? My code works for integers, such as 25 and 60. But if I let the octal number to be non-integer, the return value truncates the digits after the decimal point. How could I edit this one?
import math
def octalToDecimal(octalNumber):
decimalNumber=0
i = 0
while (math.floor(octalNumber) != 0):
rem = math.floor(octalNumber) % 10
octalNumber /= 10
decimalNumber += rem * 8**i
i+=1
return decimalNumber
q=25.63
p=octalToDecimal(q)
print("The decimal representatation of {} is {}.".format(q, p))
"."
, your program can handle the integer part and the fractional part of 63 in your example would result in $6/8 + 3/8^2$ in decimal. – jorisperrenet Mar 14 '23 at 15:39