From 74d96ab3558120b6810aa3f613e091774aefeca3 Mon Sep 17 00:00:00 2001 From: Jawpral <34590600+Jawpral@users.noreply.github.com> Date: Mon, 9 Dec 2019 03:57:42 +0530 Subject: [PATCH] Fixed issue #1368 (#1482) * Changed as suggested Now return in same format as oct() returns * Slight change * Fixed issue #1368, return values for large number now is fixed and does not return in scientific notation * Update decimal_to_octal.py --- conversions/decimal_to_octal.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/conversions/decimal_to_octal.py b/conversions/decimal_to_octal.py index 0b005429d..b1829f1a3 100644 --- a/conversions/decimal_to_octal.py +++ b/conversions/decimal_to_octal.py @@ -6,8 +6,12 @@ import math # https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/DecimalToOctal.js -def decimal_to_octal(num): - """Convert a Decimal Number to an Octal Number.""" +def decimal_to_octal(num: int) -> str: + """Convert a Decimal Number to an Octal Number. + + >>> all(decimal_to_octal(i) == oct(i) for i in (0, 2, 8, 64, 65, 216, 255, 256, 512)) + True + """ octal = 0 counter = 0 while num > 0: @@ -16,7 +20,7 @@ def decimal_to_octal(num): counter += 1 num = math.floor(num / 8) # basically /= 8 without remainder if any # This formatting removes trailing '.0' from `octal`. - return "{0:g}".format(float(octal)) + return f"0o{int(octal)}" def main():