【问题标题】:Show decimal type in listbox VB2008在列表框中显示十进制类型 VB2008
【发布时间】:2017-06-29 01:29:10
【问题描述】:

我的 VB 2008 项目有问题。 我有 5 个仅包含数字的文本框。从所有输入的值将显示在列表框中并按升序排序。 我在下面使用此代码

Private Sub InptBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InptBtn.Click
    Dim List As New List(Of Double)
    Dim chkList As New Integer
    Dim getData() As String = {Inpt1.Text, Inpt2.Text, Inpt3.Text, Inpt4.Text, Inpt5.Text, Inpt6.Text}

    ' empty check
    For idx As Integer = 0 To getData.Length - 1
        chkList += getData(idx).Trim.Length
    Next

    If chkList = 0 Then
        MessageBox.Show("EMPTY!", "WARNING!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Return
    End If

    ' numeric check
    Dim d1 As Double = 0

    For idx As Integer = 0 To getData.Length - 1
        If Double.TryParse(getData(idx), d1) Then
            List.Add(d1)
        End If
    Next

    If List.Count = 0 Then
        MessageBox.Show("Please fill with number!", "WARNING!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Return
    End If

    List.Sort()
    ListBox.DataSource = List

End Sub

这是工作!但我有1个问题。 如果我尝试输入

0.0000000000001 或 0.00000000000000000002

它是这样显示的

1E-13 或 2E-20

我尝试使用ToString 方法并将列表类型更改为String 后排序如下代码,但它不起作用。

For idx As Integer = 0 To getData.Length - 1
        If Double.TryParse(getData(idx), d1) Then
            List.Add(d1.ToString())
        End If
    Next

我可以在输入Decimal 类型时显示所有输入的值吗?或者有什么方法可以用其他类型来展示它? 在 Listbox 中如下所示:

0.0000000000001 或 0.00000000000000000002

非常感谢!

【问题讨论】:

    标签: vb.net listbox format-string


    【解决方案1】:

    你可以试试这个吗?

    For idx As Integer = 0 To getData.Length - 1
        If Double.TryParse(getData(idx), d1) Then
            List.Add(FormatNumber(d1.ToString, 20))
        End If
    Next
    

    【讨论】:

    • 对不起,没用。如果我输入0.00001,它将显示0.0000100000000000000
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 2022-01-22
    相关资源
    最近更新 更多