Home > Mobile >  How to format integers in Python?
How to format integers in Python?

Time:12-08

I have the numbers:

'115000000000'
'10000000'
'99700000000'

I need to make them look like this:

'1150,00000000'
'0,10000000'
'997,00000000'

or

'1150'
'0,1'
'997'

CodePudding user response:

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)

CodePudding user response:

n = ['115000000000', '10000000', '99700000000']
nn= [str(  float(float(element)/100000000)   ) for element in n]

results in nn to be:

['1150.0', '0.1', '997.0']
  • Related