def _color(val):
  """
  Parse string as hex color string. The scim CSV does some dumb things like
  truncate, convert to float, and remove #, so fix all that crap.

  >>> _color('#ff0000')
  '#ff0000'
  >>> _color('ff0000')
  '#ff0000'
  >>> _color('668800.00')
  '#668800'
  >>> _color('345')
  '#000345'
  """
  if val.startswith('#'):
    return val  # already ok
  if val.endswith('.00'):
    val = val[:-3]
  while len(val) < 6:
    val = '0' + val
  return '#' + val