Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

VS 2008 Excel 2007 precision problem and datagrids...what goes in isn't what comes out!

$
0
0
Hi,

I'm storing values typed into a datagrid in an Excel spreadsheet, but if I type a non integer number in the datagrid, when it gets stored in Excel, a load more decimal places get added to which it just seems to add random numbers to.

Code:

wks.Cells(byteSheet_Row_Count, 12).value = datagridDilution.Rows.Item(byteData_Grid_Row_Count).Cells(0).Value
The value in the datagrid is 0.17 - that column in the datagrid has some formatting on it:

Code:

datagridDilution.Columns(0).ValueType = GetType(Single)
        datagridDilution.Columns(0).DefaultCellStyle.Format = "n2"

If I check the value of the Excel cell while in debug mode, the immediate windows shows this:

?wks.Cells(byteSheet_Row_Count, 12).value
0.17000000178813934 {Double}
Double: 0.17000000178813934 {Double}

Now the 1st few values that are below 1 it messes up, but after that the rest of the numers are integers which don't get "adjusted"

I guess I could store the datagrid value in a string before passing it to Excel, but I want to know why Excel (or VB) is doing this.

Thanks

Kristian

Viewing all articles
Browse latest Browse all 42225


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>