parameters: (self, num)
return_statement: return formatted
docstring: Formats a number in engineering notation, appending a letter
          representing the power of 1000 of the original number. Some examples:
  
          >>> format_eng(0)       # for self.accuracy = 0
          ' 0'
  
          >>> format_eng(1000000) # for self.accuracy = 1,
                                  #     self.use_eng_prefix = True
          ' 1.0M'
  
          >>> format_eng("-1e-6") # for self.accuracy = 2
                                  #     self.use_eng_prefix = False
          '-1.00E-06'
  
          @param num: the value to represent
          @type num: either a numeric value or a string that can be converted to
                     a numeric value (as per decimal.Decimal constructor)
  
          @return: engineering formatted string
docstring_summary: Formats a number in engineering notation, appending a letter
          representing the power of 1000 of the original number. Some examples:
docstring_tokens: Formats a number in engineering notation appending a letter representing the power of 1000 of the original number . Some examples :
function: def __call__(self, num):
          """ Formats a number in engineering notation, appending a letter
          representing the power of 1000 of the original number. Some examples:
  
          >>> format_eng(0)       # for self.accuracy = 0
          ' 0'
  
          >>> format_eng(1000000) # for self.accuracy = 1,
                                  #     self.use_eng_prefix = True
          ' 1.0M'
  
          >>> format_eng("-1e-6") # for self.accuracy = 2
                                  #     self.use_eng_prefix = False
          '-1.00E-06'
  
          @param num: the value to represent
          @type num: either a numeric value or a string that can be converted to
                     a numeric value (as per decimal.Decimal constructor)
  
          @return: engineering formatted string
          """
          import decimal
          import math
          dnum = decimal.Decimal(str(num))
  
          if decimal.Decimal.is_nan(dnum):
              return 'NaN'
  
          if decimal.Decimal.is_infinite(dnum):
              return 'inf'
  
          sign = 1
  
          if dnum < 0:  # pragma: no cover
              sign = -1
              dnum = -dnum
  
          if dnum != 0:
              pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3))
          else:
              pow10 = decimal.Decimal(0)
  
          pow10 = pow10.min(max(self.ENG_PREFIXES.keys()))
          pow10 = pow10.max(min(self.ENG_PREFIXES.keys()))
          int_pow10 = int(pow10)
  
          if self.use_eng_prefix:
              prefix = self.ENG_PREFIXES[int_pow10]
          else:
              if int_pow10 < 0:
                  prefix = 'E-{pow10:02d}'.format(pow10=-int_pow10)
              else:
                  prefix = 'E+{pow10:02d}'.format(pow10=int_pow10)
  
          mant = sign * dnum / (10**pow10)
  
          if self.accuracy is None:  # pragma: no cover
              format_str = u("{mant: g}{prefix}")
          else:
              format_str = (u("{{mant: .{acc:d}f}}{{prefix}}")
                            .format(acc=self.accuracy))
  
          formatted = format_str.format(mant=mant, prefix=prefix)
  
          return formatted
function_tokens: def __call__ ( self , num ) : import decimal import math dnum = decimal . Decimal ( str ( num ) ) if decimal . Decimal . is_nan ( dnum ) : return 'NaN' if decimal . Decimal . is_infinite ( dnum ) : return 'inf' sign = 1 if dnum < 0 : # pragma: no cover sign = - 1 dnum = - dnum if dnum != 0 : pow10 = decimal . Decimal ( int ( math . floor ( dnum . log10 ( ) / 3 ) * 3 ) ) else : pow10 = decimal . Decimal ( 0 ) pow10 = pow10 . min ( max ( self . ENG_PREFIXES . keys ( ) ) ) pow10 = pow10 . max ( min ( self . ENG_PREFIXES . keys ( ) ) ) int_pow10 = int ( pow10 ) if self . use_eng_prefix : prefix = self . ENG_PREFIXES [ int_pow10 ] else : if int_pow10 < 0 : prefix = 'E-{pow10:02d}' . format ( pow10 = - int_pow10 ) else : prefix = 'E+{pow10:02d}' . format ( pow10 = int_pow10 ) mant = sign * dnum / ( 10 ** pow10 ) if self . accuracy is None : # pragma: no cover format_str = u ( "{mant: g}{prefix}" ) else : format_str = ( u ( "{{mant: .{acc:d}f}}{{prefix}}" ) . format ( acc = self . accuracy ) ) formatted = format_str . format ( mant = mant , prefix = prefix ) return formatted