I tried to use one %
, and double %%
, both seem to multiply my number to 100 times bigger.
This is what it looks like:
percent_format = workbook.add_format({'num_format': '0.00%'})
result: 9403.00%
percent_format = workbook.add_format({'num_format': '0.00%%'})
result: 9403.00%%
percent_format = workbook.add_format({'num_format': '0.00'})
result: 94.03
, which is what I want, I just need to append a %
on the end.
Any thoughts?
To obtain the character "%" in a format string, enter "%%", e.g. printf("The percentage is %d %%. *n",5); yields The percentage is 5 %. Most users will find that "%g" is the best choice for printing out floating point numbers.
The % symbol is used in Python with a large variety of data types and configurations. %s specifically is used to perform concatenation of strings together. It allows us to format a value inside a string. It is used to incorporate another string within a string.
You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.
The Format Class has a lot of detail about formatting with XlsxWriter. Around halfway there is a section on format.set_num_format() though this does not specifically mention formatting for percentage sign. It can be achieved so:
percent_format = workbook.add_format({'num_format': '0.00"%"'})
This merely appends %
(say 9
to 9%
) without any conversion from say 9
to 900%
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With