Peter Roche
Peter Roche

Reputation: 345

Access 2010 + Datagridview Decimal Issue

I seem to be having and issue with the decimal option in access 2010.

The images below demonstrate the problem that I am having, one image shows normal 0's in empty cells within Access 2010, however when this data is moved to a datagridview the number becomes 3 decimal places (0.000).

The final image displays the options that have been selected within the Qty Open field, this is for information purposes to try and get to the bottom of the problem.

The main issue I believe that is causing this is the Scale option in Access, when this is removed the datagridview displays the number without the additional decimal places. However by removing this option disallows me to enter any decimal places.

1 2

3

Upvotes: 1

Views: 723

Answers (2)

Conrad Frix
Conrad Frix

Reputation: 52675

You don't want to modify the underlying datatype on the Access Database for this. Instead you should be modifying how the data is displayed

To do this just set the Format Property on the Column's DefaultCellStyle using a Custom Format Specifier using the Digit placeholder #

Replaces the pound sign with the corresponding digit if one is present; otherwise, no digit appears in the result string

e.g.

this.dataGridView1.Columns["Wastage"].DefaultCellStyle.Format = "#,0.###";

Upvotes: 1

nawfal
nawfal

Reputation: 73283

All you need is display the end result properly. Try this:

private decimal GetDecimalValue(decimal d)
{
    return d / 1.00000000000000000000000000000m;
}

Call this before you display the result.

Upvotes: 0

Related Questions