Fraction to Recurring Decimal

Medium

Description

Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses.

Examples

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

1/2 = 0.5

Input:numerator = 2, denominator = 3
Output:"0.(6)"
Explanation:

2/3 = 0.666... with 6 repeating.

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

4/333 = 0.012012... with 012 repeating.

Constraints

  • -2³¹ ≤ numerator, denominator ≤ 2³¹ - 1
  • denominator != 0

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!