如何格式化 Python 中的整数?
How to format integers in Python?
我有号码:
'115000000000'
'10000000'
'99700000000'
我需要让它们看起来像这样:
'1150,00000000'
'0,10000000'
'997,00000000'
或
'1150'
'0,1'
'997'
n = ['115000000000', '10000000', '99700000000']
nn= [str( float(float(element)/100000000) ) for element in n]
结果 nn 为:
['1150.0', '0.1', '997.0']
numbers = ['115000000000', '10000000', '99700000000']
for number in numbers:
number = float(number)/100_000_000 # number seems to be a string? Also _ improves readability
output = f'{number:.8f}'.replace('.', ',') # 8 = numbers of decimal digits (decimal number -> float -> f)
我有号码:
'115000000000'
'10000000'
'99700000000'
我需要让它们看起来像这样:
'1150,00000000'
'0,10000000'
'997,00000000'
或
'1150'
'0,1'
'997'
n = ['115000000000', '10000000', '99700000000']
nn= [str( float(float(element)/100000000) ) for element in n]
结果 nn 为:
['1150.0', '0.1', '997.0']
numbers = ['115000000000', '10000000', '99700000000']
for number in numbers:
number = float(number)/100_000_000 # number seems to be a string? Also _ improves readability
output = f'{number:.8f}'.replace('.', ',') # 8 = numbers of decimal digits (decimal number -> float -> f)