I want to print a decimal using a comma as decimal separator. When I do this
import locale
locale.setlocale(locale.LC_ALL, 'nl_NL')
'{0:#.2n}'.format(1.1)
I get '1,1'
. The comma is there, but the precision is only one, whereas I set it to two. How come?
Note this format is constructed as follows:
#
: "The'#'
option causes the "alternate form" to be used for the conversion. ... In addition, for'g'
and'G'
conversions, trailing zeros are not removed from the result.".2
: Precision.n
: "Number. This is the same as'g'
, except that it uses the current locale setting to insert the appropriate number separator characters."
where the quotes come from the manual: Format Specification Mini-Language.
Using {.2f}
as suggested in the comments does not do what I want either: '1.10'
. The precision is correct, but the comma from the locale is ignored.