top and bottom. Write the fraction top / bottom as a decimal string.
- If the fraction is a whole number, return just the integer part with no point: "7", "-3".
- If the decimal expansion terminates, return all of it: "0.625".
- If the fractional part repeats forever, wrap the repeating block in parentheses: "0.(3)", "2.41(6)". The parentheses open as early as possible and the block inside them is the shortest one.
A negative result starts with a minus sign; zero has no sign.top=5, bottom=8 → '0.625'
5/8 = 0.625, which terminates, so no parentheses are needed.
top=-29, bottom=12 → '-2.41(6)'
29/12 = 2.41666…: after the digits 4 and 1 the 6 repeats forever. The result is negative because the two inputs have opposite signs.
top=3, bottom=37 → '0.(081)'
3/37 = 0.081081…, the three-digit block 081 repeats.
top=5, bottom=8
'0.625'
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.