none
vb.net 'Control the decimal places a comma-separated value ' RRS feed

  • Question

  • I have a comma separated value which is 12.03E+03 , 15.000E+03.

    How to change the them to 2 decimal places?

    pls reply me 

    Tuesday, October 3, 2017 2:19 AM

All replies

  • Hi

    Try this. Gets a list of strings formated to 2 decimal places.

    Dim res As New List(Of String) Dim v As String = "12.03E+03 , 15.000E+03" For Each s As String In v.Split(","c) res.Add(GetDouble(s).ToString("#.00")) Next

        Function GetDouble(s As String) As Double
            ' change string to Double (or zero)
            Dim v As Double = 0.0
            If Double.TryParse(s, v) Then Return v
            Return 0.0
        End Function



    Regards Les, Livingston, Scotland


    Tuesday, October 3, 2017 2:44 AM
  • Hi chewmj,

    In addition to the above post, you can also try the following method, please refer to:

    Dim v As String = "12.03E+03 , 15.000E+03"
            Dim a As Decimal = 0.00
            Dim value() As String = v.Split(",").ToArray()
            For i As Integer = 0 To value.Count - 1
                a = Convert.ToDecimal(Decimal.Parse(value(i).ToString(), System.Globalization.NumberStyles.Float))
                Console.WriteLine(a.ToString("#.00"))
            Next

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 3, 2017 7:14 AM
    Moderator
  • Hi chewmj,

    Anything update? Have you solved your issue now? If yes, please remember to close your thread by marking the helpful post as answer, it is beneficial to other community members who face the same issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 19, 2017 7:44 AM
    Moderator