2018年12月23日 星期日

[python] How to format your output

#Code
strFormatNum = "{:03d}".format(1)      # 1 -> 001
print('strFormatNum = ', strFormatNum)


#Result

strFormatNum =  001




#Code
st_ele = "{:2.2f}".format(st_ele)   # 1.232323 -> 1.23


#Code
'{:.2%}'.format(0.9995)
'99.95%'


Reference
https://stackoverflow.com/questions/31964930/python-string-formatting-with-percent-sign/31964980