# 分数到小数

<p>给定两个整数，分别表示分数的分子 <code>numerator</code> 和分母 <code>denominator</code>，以 <strong>字符串形式返回小数</strong> 。</p>

<p>如果小数部分为循环小数，则将循环的部分括在括号内。</p>

<p class="MachineTrans-lang-zh-CN">如果存在多个答案，只需返回 <strong>任意一个</strong> 。</p>

<p class="MachineTrans-lang-zh-CN">对于所有给定的输入，<strong>保证</strong> 答案字符串的长度小于 <code>10<sup>4</sup></code> 。</p>

<p> </p>

<p><strong>示例 1：</strong></p>

<pre>
<strong>输入：</strong>numerator = 1, denominator = 2
<strong>输出：</strong>"0.5"
</pre>

<p><strong>示例 2：</strong></p>

<pre>
<strong>输入：</strong>numerator = 2, denominator = 1
<strong>输出：</strong>"2"
</pre>

<p><strong>示例 3：</strong></p>

<pre>
<strong>输入：</strong>numerator = 2, denominator = 3
<strong>输出：</strong>"0.(6)"
</pre>

<p><strong>示例 4：</strong></p>

<pre>
<strong>输入：</strong>numerator = 4, denominator = 333
<strong>输出：</strong>"0.(012)"
</pre>

<p><strong>示例 5：</strong></p>

<pre>
<strong>输入：</strong>numerator = 1, denominator = 5
<strong>输出：</strong>"0.2"
</pre>

<p> </p>

<p><strong>提示：</strong></p>

<ul>
	<li><code>-2<sup>31</sup> <= numerator, denominator <= 2<sup>31</sup> - 1</code></li>
	<li><code>denominator != 0</code></li>
</ul>


## template

```python

class Solution(object):
    def fractionToDecimal(self, numerator, denominator):

        if numerator < 0 and denominator < 0:
            numerator, denominator = -numerator, -denominator

        u = (numerator < 0) ^ (denominator < 0)

        numerator = abs(numerator)
        denominator = abs(denominator)
        numerator = numerator % denominator

        if numerator == 0:
            return str(numerator // denominator)

        s = str(abs(numerator) // denominator) + "."
        q = {}
        l = []
        while numerator < denominator:
            numerator = numerator * 10
            l.append(numerator)
            q[numerator] = numerator // denominator
        numerator = numerator % denominator * 10

        while numerator not in q and numerator != 0:
            l.append(numerator)
            q[numerator] = numerator // denominator
            numerator = numerator % denominator
            numerator = numerator * 10

        for i in range(0, len(l)):
            if numerator == l[i]:
                s = s + "("
            s = s + str(q[l[i]])
        if "(" in s:
            s = s + ")"
        if u:
            s = "-" + s
        return s

```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```