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

2
  • 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? Commented Jul 23, 2021 at 12:45
  • Does this answer your question? Is floating point math broken? Commented Jul 23, 2021 at 13:52

1 Answer 1

2

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

Read more here.

Sign up to request clarification or add additional context in comments.

2 Comments

has the decimal data type in SQL Server resource consuming with float ? Thank for your confirm.
@NguyenLam Read the answer of Iman and you will find the answer to this question + more. stackoverflow.com/questions/1056323/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.