我想加密一个不超过N
个小数的数字。我使用的进程有时生成的小数位数少于N
,因此我需要将其余的零填充到左侧。我尝试了这个:
N = 5 # The number of decimals needed for encryption
encrypted = '%0Nd' % (x) # here x is a number used to encrypte the original number
但是
N
中的encrypted
应该是数字优先级。 最佳答案
encrypted = '{:0{width}d}'.format(x, width=N)