mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improve the format_number template function, permitting leaving off the {} characters when using basic templates. This allows format_number to be used in Template Program Mode, where the { } characters are not permitted.
This commit is contained in:
parent
bff275fc7e
commit
66a0b28b93
@ -853,12 +853,16 @@ class BuiltinFormatNumber(BuiltinFormatterFunction):
|
|||||||
'"{0:,d}" or "${0:5,.2f}". The field_name part of the '
|
'"{0:,d}" or "${0:5,.2f}". The field_name part of the '
|
||||||
'template must be a 0 (zero) (the "{0:" in the above examples). '
|
'template must be a 0 (zero) (the "{0:" in the above examples). '
|
||||||
'See the template language and Python documentation for more '
|
'See the template language and Python documentation for more '
|
||||||
'examples. Returns the empty string if formatting fails.'
|
'examples. You can leave off the leading "{0:" and trailing '
|
||||||
|
'"}" if the template contains only a format. Returns the empty '
|
||||||
|
'string if formatting fails.'
|
||||||
)
|
)
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, val, template):
|
def evaluate(self, formatter, kwargs, mi, locals, val, template):
|
||||||
if val == '' or val == 'None':
|
if val == '' or val == 'None':
|
||||||
return ''
|
return ''
|
||||||
|
if not '{' in template:
|
||||||
|
template = '{0:' + template + '}'
|
||||||
try:
|
try:
|
||||||
v1 = float(val)
|
v1 = float(val)
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user