def num_repr(num):
 if (num <= 9999):
  return str(num)
 def digit_count(x):
  ' Return number of digits. '
  return int((math.floor(math.log10(x)) + 1))
 digits = digit_count(num)
 sig = (3 if ((digits % 3) == 0) else 2)
 rounded = int(round(num, int((sig - digits))))
 digits = digit_count(rounded)
 suffix = '_kmBTqXYX'[((digits - 1) // 3)]
 front = (3 if ((digits % 3) == 0) else (digits % 3))
 if (not (front == 1)):
  return (str(rounded)[0:front] + suffix)
 return (((str(rounded)[0] + '.') + str(rounded)[1]) + suffix)

def num_repr ( num ) : if ( num <= 9999 ) : return str ( num ) def digit_count ( x ) : return int ( ( math . floor ( math . log10 ( x ) ) + 1 ) ) digits = digit_count ( num ) sig = ( 3 if ( ( digits % 3 ) == 0 ) else 2 ) rounded = int ( round ( num , int ( ( sig - digits ) ) ) ) digits = digit_count ( rounded ) suffix = '_kmBTqXYX' [ ( ( digits - 1 ) // 3 ) ] front = ( 3 if ( ( digits % 3 ) == 0 ) else ( digits % 3 ) ) if ( not ( front == 1 ) ) : return ( str ( rounded ) [ 0 : front ] + suffix ) return ( ( ( str ( rounded ) [ 0 ] + '.' ) + str ( rounded ) [ 1 ] ) + suffix )
return up to four digit string representation of a number .