0

This should be easy..

I have a datatable with a values like '1234.5'. When I convert that to a string it drops the decimal and becomes '1234'.

For Each row As DataRow In dt.Rows
    myvalue = row("ColumnName").toString

    'some other stuff with myvalue
Next

How can I make the output display what ever is in the cell as a complete string (including decimal numbers)? '1234.5'

thanks!

malt_man
  • 403
  • 1
  • 6
  • 21
  • Dont add the `ToString` and make sure your variable `myvalue` is a double data type... Then use `Convert.ToString(myvalue)` – Trevor Aug 13 '15 at 00:52
  • It's the strangest thing... I confirmed that it is a type double. I tried displaying the double straight from the cell and it's still truncating the decimals. It's only happening to this one column. I have other columns that are doubles as well and they are displaying the decimal. I'm about to go crazy. – malt_man Aug 13 '15 at 17:24
  • I figured out the issue. It has to do with the way I was filling the datatable. I was using Microsoft.Jet.OLEDB.4.0 with a select * statement. The weird thing is that if the first row in the column has a decimal, it will keep the decimal for the rest of the rows. But if the first row does not have a decimal, it truncates all the remaining rows.... what the heck! Now I need to figure out how to turn that off. – malt_man Aug 13 '15 at 17:54
  • Correct, that was an issue I actually had come across before a time or two. Glad you found it! What data type is that column, you want to make sure it's the correct type. If you have mixed types this can cause detrimental effects in the end. – Trevor Aug 13 '15 at 17:56
  • This is my exact issue haha: http://stackoverflow.com/questions/3232281/oledb-mixed-excel-datatypes-missing-data – malt_man Aug 13 '15 at 18:06
  • I was just searching the wrong thing. Thanks for your help! – malt_man Aug 13 '15 at 18:06

1 Answers1

-1

How about something like this'

Imports System.Data
Module Module1

    Sub Main()
        Dim dt As New DataTable

        Dim resutls As List(Of String) = dt.AsEnumerable().Select(Function(x) x.Field(Of Double)("ColumnName").ToString()).ToList()

    End Sub

End Module​
jdweng
  • 33,250
  • 2
  • 15
  • 20