Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

A rational number can be represented using up to three parts: &lt;IntegerPart&gt;, &lt;NonRepeatingPart&gt;, and a &lt;RepeatingPart&gt;. The number will be represented in one of the following three ways:


	&lt;IntegerPart&gt;

	
		For example, 12, 0, and 123.
	
	
	&lt;IntegerPart&gt;&lt;.&gt;&lt;NonRepeatingPart&gt;
	
		For example, 0.5, 1., 2.12, and 123.0001.
	
	
	&lt;IntegerPart&gt;&lt;.&gt;&lt;NonRepeatingPart&gt;&lt;(&gt;&lt;RepeatingPart&gt;&lt;)&gt;
	
		For example, 0.1(6), 1.(9), 123.00(1212).
	
	


The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:


	1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).


&nbsp;
Example 1:

Input: s = "0.(52)", t = "0.5(25)"
Output: true
Explanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.


Example 2:

Input: s = "0.1666(6)", t = "0.166(66)"
Output: true


Example 3:

Input: s = "0.9(9)", t = "1."
Output: true
Explanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1.  [See this link for an explanation.]
"1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".


&nbsp;
Constraints:


	Each part consists only of digits.
	The &lt;IntegerPart&gt; does not have leading zeros (except for the zero itself).
	1 &lt;= &lt;IntegerPart&gt;.length &lt;= 4
	0 &lt;= &lt;NonRepeatingPart&gt;.length &lt;= 4
	1 &lt;= &lt;RepeatingPart&gt;.length &lt;= 4


class Solution:
    # inspired from:
    # https://coolconversion.com/math/recurring-decimals-as-a-fraction/
    # to which we wouldn't have access during interview.

    import typing
    def isRationalEqual(self, s: str, t: str) -> bool:

        # intuition:
        # write each numbes as fraction: num / den
        # then compare the two fractions.

        num1, den1 = self.toFraction(s)
        num2, den2 = self.toFraction(t)

        return den1 * num2 == den2 * num1

    def toFraction(self, s: str) -> typing.Tuple[int, int]:
        if "." not in s:
            return int(s), 1

        intp, frac = s.split(".")
        # decimal dot, but no repeating part:
        # xyz.abc = xyzabc / 1000
        if "(" not in frac:
            ifrac = int(frac) if len(frac) > 0 else 0
            num = int(intp) * (10 ** len(frac)) + ifrac
            den = 10 ** len(frac)
            return num, den

        # this is for cases like a.b(c)
        # let n = a.b(c)
        # then, 10^(len(b+c)) * n = abc.(c)
        # and 10^(len(b)) * n = ab.(c)
        # subtract the two, and solve for n:
        # n = (abc - ab) / (10^len(b + c) - 10^len(b))
        frac, repfrac = frac.split("(")
        repfrac = repfrac[:-1]

        iintp = int(intp)
        ifrac = int(frac) if len(frac) > 0 else 0
        irep = int(repfrac)

        return (
            (iintp * (10 ** (len(frac + repfrac))) + ifrac * 10 ** len(repfrac) + irep) - (iintp * 10 ** len(frac) + ifrac),
            (10** len(frac+repfrac) - 10 **len(frac))
        )
    ```
class Solution {

    private List<Double> ratios = Arrays.asList(1.0, 1.0 / 9, 1.0 / 99, 1.0 / 999, 1.0 / 9999);

    public boolean isRationalEqual(String S, String T) {
        return Math.abs(computeValue(S) - computeValue(T)) < 1e-9;
    }

    private double computeValue(String s) {
        if (!s.contains("(")) {
            return Double.valueOf(s);
        } else {
            double intNonRepeatingValue = Double.valueOf(s.substring(0, s.indexOf('(')));
            int nonRepeatingLength = s.indexOf('(') - s.indexOf('.') - 1;
            int repeatingLength = s.indexOf(')') - s.indexOf('(') - 1;
            int repeatingValue = Integer.parseInt(s.substring(s.indexOf('(') + 1, s.indexOf(')')));
            return intNonRepeatingValue + repeatingValue * Math.pow(0.1, nonRepeatingLength) * ratios.get(repeatingLength);
        }
    }
}
class Solution {
public:
    double toDouble(string s){

       // Strings for each integral, fractional, and repeating part
       string in="", fn="", rn="";

        int i=0;

        // Integral
        while(i<s.size() && s[i]!='.'){ in+=s[i]; i++; }
        // Fractional
        i++;
        while(i<s.size() && s[i]!='('){ fn+=s[i]; i++; }
        // Repeating
        i++;
        while(i<s.size() && s[i]!=')'){ rn+=s[i]; i++; }

         // Number
        double a = 0;

        // Adding integral part
        if(!in.empty()) a=stoi(in);

        i=0;

        // Adding fractional part
        while(i<fn.size()){
            a = a*10 + fn[i] - '0';
            i++;
        }

        // Adding repeating part
        if(i < 8){
            // If repeatig part isn't there then just add 0s
            if(rn.size() == 0){
                while(i <= 8){ a*=10;i++; }
            }

            else {
                int j=0;
                while(i <= 8){
                    a = a*10 + rn[j%rn.size()] - '0';
                    j++;
                    i++;
                }
            }
        }
        // Return number/10^8
        return a/10e8;
    }

    bool isRationalEqual(string s, string t) {
        // Find absolute differance till 8 digits after decimal and compar if its lesser
        double ans = abs(toDouble(s) - toDouble(t));
        return ans < 0.000000002;
    }
};
var isRationalEqual = function(s, t) {
    return calculate(s) === calculate(t);

    function calculate(v) {
        let start = v.split('(')[0] || v;
        let newer = v.split('(')[1] && v.split('(')[1].split(')')[0] || '0';

        start = start.includes('.') ? start : start + '.';
        newer = newer.padEnd(100, newer);

        return parseFloat(start + newer);
    }
};
Equal Rational Numbers