0

Im passing a datatable as Datasource to a DataGridView, but when dealing with decimals, they are displayed in random notations.

In a column where all the values are 19,00( i printed them in console from the dataTable just before passing it as source, and when inserted into that datatable they are inserted as a 19,00) some of the values are displayed as 19,01197604... others as 18,966689, same thing happens with another column, where the numbers are diverse, but some of them are displayed correctly

JRB
  • 1,943
  • 1
  • 10
  • 9
cg7
  • 189
  • 1
  • 15
  • 2
    Then they are not [decimals](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/decimal-data-type), they are [floats](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/single-data-type), and they are genuinely [not equal to 19](https://stackoverflow.com/q/588004/11683). If that is okay and you simply want to round the displayed value to two decimal points, then it's a Possible duplicate of [Number Format For Datagridview in C#](https://stackoverflow.com/q/18299040/11683) – GSerg Sep 17 '18 at 20:28
  • the thing is, why are they floats? im passing the value 19,00 to the table, where does all the other things come from? (im using sqlite, wich may be the issue since sqlite uses field "REAL" bu i doesnt really care what you put there) – cg7 Sep 17 '18 at 20:33
  • `why are they floats` - because that is [what `REAL` means in sqlite](https://www.sqlite.org/datatype3.html). `where does all the other things come from` - from [how these numbers work](https://stackoverflow.com/q/588004/11683). – GSerg Sep 17 '18 at 20:37
  • Thank you, finally managed to understand it, so, any advice of how should then i save the decimals(appart from "dont use sqlite")? – cg7 Sep 17 '18 at 20:40
  • 1
    Assuming you are using the official SQLite provider, define the column as decimal – Ňɏssa Pøngjǣrdenlarp Sep 17 '18 at 22:55
  • yep, that did the trick (even when in the sqlite docs they decided to tell you that they just use real and integer, end even then just for affinity). Thank you, solved – cg7 Sep 18 '18 at 13:45

0 Answers0