Skip to content

Practice Fraction to Recurring Decimal

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#166
LeetCode Problem

Fraction to Recurring Decimal

Problem Statement

Convert numerator divided by denominator to a decimal string, including a minus sign when needed. If the expansion terminates, return its finite form. Otherwise enclose the repeating part of the fractional digits in parentheses; any valid representation is accepted. The resulting string is guaranteed to have fewer than 10^4 characters.

Source: Fraction to Recurring Decimal on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
numerator = 1, denominator = 2
Output
"0.5"

# Example 2

Input
numerator = 2, denominator = 1
Output
"2"

# Example 3

Input
numerator = 4, denominator = 333
Output
"0.(012)"

Constraints

-2^31 <= numerator, denominator <= 2^31 - 1
denominator != 0

Related LeetCode Problems

Practice more problems similar to Fraction to Recurring Decimal.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.