'Format quantities using the new-style python formatting codes
as specifiers for the number.
If the format specifier correctly applies itself to the value,
then it is used to format only the value. If it cannot be
applied to the value, then it is applied to the whole string.'

def __format__(self, format_spec):

    try:
        value = format(self.value, format_spec)
        full_format_spec = u's'
    except ValueError:
        value = self.value
        full_format_spec = format_spec
    return format(u'{0}{1:s}'.format(value, self._unitstr), full_format_spec)
