1

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

Peter Roche
  • 335
  • 2
  • 6
  • 18
  • 2
    When you say datagridview, do you mean in c# or vb.net? Can you clarify your tags? BTW the tag `access` is pretty much valueless. – Fionnuala Mar 30 '12 at 10:07
  • hi @Remou Its in c# and tags have been modified – Peter Roche Mar 30 '12 at 15:51
  • related to: http://stackoverflow.com/questions/8898342/why-is-that-i-get-zeroes-added-to-decimal-values-that-i-am-pulling-from-ms-acces – nawfal Mar 30 '12 at 16:43
  • Not the same, that is why I said "related". Moreover nowhere in your question you mentioned about dataadapters. Hence my answer too didnt account that. Anyway you got a solution.. – nawfal Mar 31 '12 at 08:03

2 Answers2

1

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.###";
Conrad Frix
  • 51,984
  • 12
  • 96
  • 155
  • Thank you very much for your answer, however this doesn't quite fix the issue i'm having. I'm trying to get the datagridview to just display 0 unless decimal numbers are entered which will display at the correct decimal. – Peter Roche Mar 30 '12 at 16:18
  • @PeterRoche doh completely misunderstood the target formatting. I updated the answer – Conrad Frix Mar 30 '12 at 16:27
  • Thank you very much, only a small issue which I will edit in the answer, as the default value in the database is 0 the current code would display 00 by default, so I changed it to "#,0.###" which now does as I need. I very much appretiate the answer and will mark it as an accepted answer. – Peter Roche Mar 30 '12 at 16:33
  • @PeterRoche nice. I've updated the answer to include your fix to the `00` problem – Conrad Frix Mar 30 '12 at 16:38
  • Excellent, thank you very much for your assistance with this problem. – Peter Roche Mar 30 '12 at 16:51
0

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.

nawfal
  • 70,104
  • 56
  • 326
  • 368
  • I don't think I'm able to do that as im using dataadapters to display the data. – Peter Roche Mar 30 '12 at 16:27
  • then pls show the code you are using so that we know. I could help more if I could see how you are displaying data – nawfal Mar 30 '12 at 16:29
  • Thank you for your answer but Conrad Fix has managed to solve it, as there was a dataadapter being used it seems I needed something that would convert the values after populating the datagridview. – Peter Roche Mar 30 '12 at 16:36