Inserting a value into a SQL floating point column generates a weird result

I am working on an outdated ASP application. I am trying to insert a value (40.33) into a SQL Server 2000 field, which is a float type. Each place that I see (through some registration) in the application sends 40.33 to the Stored Procedure. When I run SQL Profiler against a database during a call, the value that I see in the trace is 4.033000183105469e + 001

Where is all the excess garbage (183105469) located?

Why, when I switch to 40 or 40.25, is there nothing more?

Is this just one of the weird side effects of using float? When I write something, I usually use money or decimals or something else, so I am not familiar with the float data type.

+4
source share
3 answers

Yes, this is an odd, though well - known , side effect of using FLOAT.

In Microsoft SQL Server, you must use exact numeric data types such as NUMERIC, DECIMAL , MONEY, or SMALLMONEY if you need accurate digits with a scale.

Do not use FLOAT.

+8
source

I think this is probably just a problem with accuracy - the 0.33 part of the number cannot be represented exactly in binary format - this is probably the closest you can get.

0
source

The problem is that floats are not 100% accurate. If you need your numbers to be precise (especially when dealing with monetary values) ... you should use the decimal type.

0
source

All Articles