sidpy.base.string_utils.format_quantity

sidpy.base.string_utils.format_quantity(value, unit_names, factors, decimals=2)[source]

Formats the provided quantity such as time or size to appropriate strings

Parameters:
  • value (number) – value in some base units. For example - time in seconds

  • unit_names (array-like) – List of names of units for each scale of the value

  • factors (array-like) – List of scaling factors for each scale of the value

  • decimals (uint, optional. default = 2) – Number of decimal places to which the value needs to be formatted

Returns:

String with value formatted correctly

Return type:

str

Examples

>> # If sidpy.string_utils.format_time() were not available, we could >> # get the same functionality via: >> import sidpy >> units = [‘msec’, ‘sec’, ‘mins’, ‘hours’] >> factors = [0.001, 1, 60, 3600] >> time_value = 14497.34 >> str_form = sidpy.string_utils.format_quantity(time_value,units,factors) >> print(‘{} seconds = {}’.format(14497.34, str_form))

See also

sidpy.string_utils.format_size, sidpy.string_utils.format_time