Reduces the string representation of a number.

  If the number is of the format n.00..., returns n.
  If the decimal portion of the number has a repeating decimal, followed by up to two trailing
  numbers, such as:

  0.3333333

  or

  0.343434346

  It will return just one instance of the repeating decimals:

  0.3

  or

  0.34

def reduce_number(num):
  """Reduces the string representation of a number.

  If the number is of the format n.00..., returns n.
  If the decimal portion of the number has a repeating decimal, followed by up to two trailing
  numbers, such as:

  0.3333333

  or

  0.343434346

  It will return just one instance of the repeating decimals:

  0.3

  or

  0.34
  """
  parts = str(num).split(".")
  if len(parts) == 1 or parts[1] == "0":
    return int(parts[0])
  else:
    match = _REPEATING_NUMBER_TRIM_RE.search(parts[1])
    if match:
      from_index, _ = match.span()
      if from_index == 0 and match.group(2) == "0":
        return int(parts[0])
      else:
        return Decimal(parts[0] + "." + parts[1][:from_index] + match.group(2))
    else:
      return num