将号码复制到文本。 [英] copy number to text.

查看:95
本文介绍了将号码复制到文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我有一个简单的(我认为)问题



我有一个数字让我们说123.

我希望如果数字是< 3添加零,所以我的新字段是4位数

123 0123

1234 1234

345 0345



我的号码字段的最小长度是3



谢谢和问候。

Hi to all.

I have an easy (i think) problem

I have a number let''s say 123.
I want if the number is < 3 to add zeroes so my new field is 4 digits
123 0123
1234 1234
345 0345

The minimum length of my number field is 3

Thanks and regards.

推荐答案

你不能用数字来做 - 前导零的数量并不重要,因为它们总是被忽略。

你可以在将数字格式化为字符串时执行此操作但是显示:

You can''t do that with numbers - the number of leading zeros doesn''t matter because they are always ignored.
You can do it when you format a number into a string for display however:
Dim val As Integer = 123
Dim formatted As String = val.ToString("D4")
Console.WriteLine("{0:D4}", val)

两者都是pr oduce0123

Will both produce "0123"


感谢您的回答和时间

我终于用
Thanks for your answer and your time
I finally solve my problem using
x.ToString.PadLeft(4, "0"c)





无论如何,再次感谢。



Anyway thanks again.


这篇关于将号码复制到文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆