{"id":22513834,"url":"https://github.com/emahtab/fraction-to-recurring-decimal","last_synced_at":"2026-02-17T02:33:58.510Z","repository":{"id":79525517,"uuid":"277620690","full_name":"eMahtab/fraction-to-recurring-decimal","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2020-07-06T19:18:34.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T12:45:32.839Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-06T18:37:17.000Z","updated_at":"2020-07-06T19:18:36.000Z","dependencies_parsed_at":"2023-05-10T17:16:12.376Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/fraction-to-recurring-decimal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/fraction-to-recurring-decimal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffraction-to-recurring-decimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffraction-to-recurring-decimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffraction-to-recurring-decimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffraction-to-recurring-decimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/fraction-to-recurring-decimal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ffraction-to-recurring-decimal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279016370,"owners_count":26085828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T03:14:36.096Z","updated_at":"2025-10-13T17:40:40.888Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fraction to recurring decimal\n## https://leetcode.com/problems/fraction-to-recurring-decimal\n\nGiven two integers representing the numerator and denominator of a fraction, return the fraction in string format.\n\nIf the fractional part is repeating, enclose the repeating part in parentheses.\n```\nExample 1:\n\nInput: numerator = 1, denominator = 2\nOutput: \"0.5\"\n\nExample 2:\n\nInput: numerator = 2, denominator = 1\nOutput: \"2\"\n\nExample 3:\n\nInput: numerator = 2, denominator = 3\nOutput: \"0.(6)\"\n\n\n```\n\n## Test Cases :\n\n**Integer.MIN_VALUE = -2147483648  ,  Integer.MAX_VALUE = 2147483647 **\n\n\n| Test case  | Explanation |\n| ------------- | ------------- |\n| 0 / 1  | Numerator is zero.  |\n| 1 / 0  | Divisor is 0, should handle it by throwing an exception but here we ignore for simplicity sake.  |\n| 20 / 4  | Answer is a whole integer, should not contain the fractional part.  |\n| 1 / 2  | Answer is 0.5, no recurring decimal.  |\n| -1 / 2 or 1 / -2  | One of the numerator or denominator is negative, fraction is negative.  |\n| -1 / -2  | Both numerator and denominator are negative, should result in positive fraction.  |\n| −2147483648 / -1  | Beware of overflow if you cast to positive.  |\n| 2 / 7  | \"0.(285714)\" |\n\n\n# Implementation :\n```java\nclass Solution {\n    public String fractionToDecimal(int numerator, int denominator) {\n    if (numerator == 0) \n        return \"0\";\n    if (denominator == 0)  \n        throw new IllegalArgumentException();\n        \n    StringBuilder fraction = new StringBuilder();\n    // If either one is negative (not both)\n    if ((numerator \u003c 0 \u0026\u0026 denominator \u003e 0) || (denominator \u003c 0 \u0026\u0026 numerator \u003e 0)) {\n        fraction.append(\"-\");\n    }\n    // Convert to Long or else abs(-2147483648) overflows\n    long dividend = Math.abs((long) numerator);\n    long divisor = Math.abs((long) denominator);\n    fraction.append(dividend / divisor);\n    long remainder = dividend % divisor;\n    if (remainder == 0) {\n        return fraction.toString();\n    }\n    fraction.append(\".\");\n    Map\u003cLong, Integer\u003e map = new HashMap\u003c\u003e();\n    while (remainder != 0) {\n        if (map.containsKey(remainder)) {\n            fraction.insert(map.get(remainder), \"(\");\n            fraction.append(\")\");\n            break;\n        }\n        map.put(remainder, fraction.length());\n        remainder *= 10;\n        fraction.append(remainder / divisor);\n        remainder %= divisor;\n    }\n    return fraction.toString();\n  }\n}\n```\n\n# References :\n1. https://www.youtube.com/watch?v=a-62yK1S1O4\n2. https://leetcode.com/problems/fraction-to-recurring-decimal/solution\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffraction-to-recurring-decimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Ffraction-to-recurring-decimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ffraction-to-recurring-decimal/lists"}