简体   繁体   English

如何在python中将尾随零添加到整数? 或者如何在python中的任何整数后添加ZEROS?

[英]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. 我没有关于如何在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 那就是我想在整数后添加3个额外的零

Multiply by 10 every time you want to add another 0. 每次要添加另一个0时乘以10。

This is the same as saying 10 to the power of how many zeroes you want. 这就像说你想要多少个零的力量一样。 In python, that would be number * (10**extraZeroCount) 在python中,这将是number * (10**extraZeroCount)

As I understand the question, the 3 extra zeros are for output purposes only. 据我所知,3个额外的零仅用于输出目的。 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 另一种方法是在每个整数之后追加3个零

int(str(number) + "000")

But I would just multiply them by 1000 但我会把它们乘以1000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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