0

I created console application where I'm using EF. I've got model where are some float variables. In my Database I also use FLOAT.

In c# I have got this value: 3,3 After insert it to my database there is value: 3,29999995231628

Why is it happening?

James Z
  • 12,209
  • 10
  • 24
  • 44
Icet
  • 678
  • 2
  • 13
  • 31
  • 13
    The `FLOAT` data type is not a precise data type. If you need exact precision then you should be using `DECIMAL` or `NUMERIC` – Tom H Mar 15 '16 at 14:08
  • 1
    Add an answer so I will accept it. Thanks for info @TomH – Icet Mar 15 '16 at 14:19
  • 1
    Possible duplicate of [Difference between Decimal, Float and Double in .NET?](http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net) – user1666620 Mar 15 '16 at 14:20
  • Possible duplicate of [Difference between numeric,float and decimal in sql server](http://stackoverflow.com/questions/1056323/difference-between-numeric-float-and-decimal-in-sql-server) – James Z Mar 15 '16 at 20:53

3 Answers3

4

The FLOAT data type is not a precise data type. If you need exact precision then you should be using DECIMAL or NUMERIC.

Tom H
  • 46,766
  • 14
  • 87
  • 128
1

This is because FLOAT is an approximate numeric datatype. You can use DECIMAL or NUMERIC, instead.

For detailed explanation, check this SO post: Difference between numeric, float and decimal in SQL Server

Community
  • 1
  • 1
Rajashekar V
  • 33
  • 1
  • 7
0

You can use real instead of float and its true to save