def eng_notation(x):
  """Converts number to string in engineering notation.

  Returns a formatted string for numeric value |x| rounded to an int in
  quasi-engineering notation, i.e:
    - if |x| is less than 1,000,000 use the standard integer format;
    - else use the <a>E<b> form where x = a * 10^b and b is a multiple of 3.
  """
  exponent = len(str(int(x))) - 1
  # Numbers up to 6 digits are easy to parse visually.
  if exponent < 6:
    return '%.7g' % x
  # Round exponent down to a multiple of 3.
  exponent = exponent - (exponent % 3)
  mantissa = x / (10 ** exponent)
  return '%.4gE^%s' % (mantissa, exponent)