Padding a fixed number with leading zeros up to a fixed length [closed]

核能气质少年 提交于 2019-11-27 07:35:07

问题


In Crystal Report using Visual Studio 2010, I am trying a to create a formula for the following scenario:

x = any number (Fixed number of 8 digits, cant be less or greater)

If Length of X is less than 8, pad the required amount of 0's in the front to make its length 8.

Eg:

X = 123
Result of Formula should be 00000123

X = 9
Result of Formula should be 00000009

Any help will be appreciated. Thanks in advance.


回答1:


ToText({table.field},"00000000") is more succinct.




回答2:


I got it

Right("0000"&{MyFieldToPad},8)

Works perfectly as I want it to.



来源:https://stackoverflow.com/questions/10989266/padding-a-fixed-number-with-leading-zeros-up-to-a-fixed-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!