简体   繁体   中英

PYTHON Format percentage as numeric

I have a question about converting a string output to a numeric output

For example:

a = "{0:.2f}%".format(float(0.21*100))

a = '21.00%'

type(a)

str

I want the output in excel to show 21.00% in the cell which format is a numeric value no a string.

Thank you~

You have to remove the percent, or you can't change it to a numeric.

float(a.replace("%", ""))

The better option is to just leave it at a = (0.21*100)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM