0

When I get data from SQL server to EntityFramework C#. My SQL server has column:

Mycolumn(float, not null)(8 byte);

C# model mapping:

public double MyColumn {get; set;}.

The SQL server saves data: 1.8(float, not null), and when I get it with dapper or EntityFramework, the column C# return 1.79999995231628. I don't understand.

Can who help me get that = 1.8 in C#. Thank you very much and have a nice day.

lovenco

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
  • 1
    This is what happens when you use floating point values. Why not use a precise data type instead? Or do you actually need floating point values? – Thom A Jul 23 '21 at 12:45
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Charlieface Jul 23 '21 at 13:52

1 Answers1

2

You need to use Decimal data type in SQL Server which is precise.

Read more here.

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
  • has the decimal data type in SQL Server resource consuming with float ? Thank for your confirm. – Nguyen Lam Jul 23 '21 at 15:52
  • @NguyenLam Read the answer of Iman and you will find the answer to this question + more. https://stackoverflow.com/questions/1056323/difference-between-numeric-float-and-decimal-in-sql-server – Misha Zaslavsky Jul 23 '21 at 15:57