stackexchange12
stackexchange12

Reputation: 652

How to Prevent rounding numbers in DataGridView using VB.Net

I have a datagridview in a windows forms vb.net application. My goal is to have any number over 0.999999999999 12 significant digits to be rounded down to 0.99999999999 11 significant digits. I want to prevent vb.net from rounding these values up to 1. This is how I'm implementing this but I can't figure out which DataGridView Event handler to use.

If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value <= 0.999999999999 Then
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = 0.99999999999
            End If

Upvotes: 0

Views: 1675

Answers (1)

Jimmy Smith
Jimmy Smith

Reputation: 2451

You can change it prior to loading it,

dataGridView1.Columns("ColumnName").DefaultCellStyle.Format = "F11"

or You can write custom logic in the dataGridView_CellFormatting event

Upvotes: 1

Related Questions