user3278877
user3278877

Reputation: 173

Python : How to format large number without comma

Problem is described below :

a = 535221324694    
b = round(a*1,024)    
print "number :"+str(b)    
>number :5.48066636487e+11    

I have tried :

print "number :"+'{0:0f}'.format(b)
>number :548066636487.000000

The result I am looking for is :

>548066636487

Upvotes: 2

Views: 6144

Answers (3)

badal16
badal16

Reputation: 509

You can cast to int e.g

print "number :"+ str(int(b))

Upvotes: 0

Kamyar Ghasemlou
Kamyar Ghasemlou

Reputation: 859

you may use:

print "number : {0:.0f}".format(b)

the zero after dot determines how many decimal digits you want after the the decimal mark. :)

extra:
you don't have to combine strings, just write them as one. It is easier to understand later.

Upvotes: 2

Kasravnd
Kasravnd

Reputation: 107347

You can convert b to int , then you dont need 0:0f in format :

b = int(round(a*1,024))    
>>> "number :"+'{}'.format(b)
'number :535221324694'

or as says in comment you may dont need to use format :

print "number:", int(b)

Upvotes: 1

Related Questions