formatter: add {:g} to remove trailing zeroes
@@ -244,11 +244,15 @@ class Placeholder:
# type then we see if we can coerce it to be. This allows
# the user to format types that normally would not be
# allowed eg '123' it also allows {:d} to be used as a
- # shorthand for {:.0f}. If the parameter cannot be
- # successfully converted then the format is removed.
+ # shorthand for {:.0f}. Use {:g} to remove insignificant
+ # trailing zeroes and the decimal point too if there are
+ # no remaining digits following it. If the parameter cannot
+ # be successfully converted then the format will be removed.
try:
if 'f' in self.format:
value = float(value)
+ if 'g' in self.format:
+ value = float(value)
if 'd' in self.format:
value = int(float(value))
output = u'{%s%s}' % (self.key, self.format)
