gpt4 book ai didi

string - 将整数格式化为 5 位数字的字符串

转载 作者:行者123 更新时间:2023-12-04 17:06:11 27 4
gpt4 key购买 nike

我需要一个基于整数的字符串,它应该总是有 5 位数字。

例子:

myInteger = 999
formatedInteger = "00999"

在经典 ASP 中执行此操作的最佳方法是什么?

最佳答案

您可以为此使用字符串操作函数。

这假定经典 ASP 与 VBScript(答案的原始版本)。

Const NUMBER_DIGITS = 5

Dim myInteger
Dim formatedInteger

myInteger = 999
formatedInteger = Right(String(NUMBER_DIGITS, "0") & myInteger, NUMBER_DIGITS)

这是一个优化的版本,包含在一个函数中,提供可变宽度的填充:

Const NUMBER_PADDING = "000000000000" ' a few zeroes more just to make sure

Function ZeroPadInteger(i, numberOfDigits)
ZeroPadInteger = Right(NUMBER_PADDING & i, numberOfDigits)
End Function

' Call in code:

strNumber = ZeroPadInteger(myInteger, 5)

关于string - 将整数格式化为 5 位数字的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/295417/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com