Python Add Comma Into Number String

前端 未结 9 1063
陌清茗
陌清茗 2020-11-29 02:37

Using Python v2, I have a value running through my program that puts out a number rounded to 2 decimal places at the end:

like this:

print (\"Total          


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 03:15

    if you are using Python 3 or above, here is an easier way to insert a comma:

    First way

    value = -12345672
    print (format (value, ',d'))
    

    or another way

    value = -12345672
    print ('{:,}'.format(value)) 
    

提交回复
热议问题