简体   繁体   中英

How to add trailing zeros to an integer in python? or How to add ZEROS after any integer in python?

I'm without clues on how to do this in Python. The problem is the following: I have for example an orders numbers like:

1
2
...
10

The output should be

1000
2000
...
10000

That is I want to add 3 extra zeros after the integer

Multiply by 10 every time you want to add another 0.

This is the same as saying 10 to the power of how many zeroes you want. In python, that would be number * (10**extraZeroCount)

As I understand the question, the 3 extra zeros are for output purposes only. There is no need to obtain integers back. Strings (or for that mater, any other type) is enough. In this vein, any of

print(a*1000)
print(str(a)+"000")
print(a,"000",sep="")

and perhaps several others, would work.

Another way could be to append 3 zeroes after every integer like

int(str(number) + "000")

But I would just multiply them by 1000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM