使用格式 VBA 指定整数的位数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22360669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:18:41  来源:igfitidea点击:

specify number of digits of Integer using Format VBA

vbams-access

提问by user3241846

I want to take an integer and display it in digits no matter what the value, e.g Int = 1 to be displayed as 001. No the integer will never be more than 3 digits. Its probably simple and im just missing the obvious.

我想取一个整数并以数字显示它,无论值是多少,例如 Int = 1 显示为 001。不,整数永远不会超过 3 位。它可能很简单,我只是错过了显而易见的事情。

CStr(Format(Int, 000)

I am concatenating the result as a string. Thanks

我将结果连接为字符串。谢谢

回答by Wayne G. Dunn

This will always show three digits:

这将始终显示三位数:

MsgBox Format(iMyInt, "000")

回答by Jimmy Smith

I think all you needed was double-quotes:

我认为你需要的只是双引号:

CStr(Format(Int, "000")