首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在文本框中保留前导零

在文本框中保留前导零
EN

Stack Overflow用户
提问于 2012-09-26 07:52:52
回答 2查看 5.2K关注 0票数 0

我需要在一个文本框中保持前导零,用于将数据输入到数据库中。它用于SKU编号。我需要能够键入前导零(例如001234567890),然后将它们输入数据库。

但是,我想不出如何将前导零保持为双精度。我不需要字符串格式,而是双精度格式。有没有办法在保留数字而不是字符串的同时做到这一点?

例如。

代码语言:javascript
运行
复制
txtProductBarcode.Text = Format(txtProductBarcode.Text, "############")
'This does not work
EN

Stack Overflow用户

发布于 2018-05-26 13:50:12

试试看这就是其中之一。您可以将整数num转换为双精度。

代码语言:javascript
运行
复制
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    Dim num As Integer
    Dim temp As String = ""
    Try
       If Regex.IsMatch(TextBox1.Text, "^[0-9 ]+$") Then
          num = Integer.Parse(TextBox1.Text)
          If num <> 0 then
             TextBox1.Text = num.ToString("D6")
             temp = num
          else
             TextBox1.ReadOnly = False
          End If
          If num.Length = 6 Then
             TextBox1.ReadOnly = True
             TextBox1.BackColor = Color.White
          ElseIf num = 0 Then
             TextBox1.ReadOnly = False
          End If
          TextBox1.SelectionStart = TextBox1.Text.Length
       End If
    Catch ex As Exception
       Msgbox(ex.Message)
    End Try
End Sub
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12592739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档