Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a value into an SQL float column generates a weird result

I am working on a legacy ASP application. I am attempting to insert a value (40.33) into a field in SQL Server 2000 that happens to be a float type. Every place I can see (via some logging) in the application is sending 40.33 to the Stored Procedure. When I run SQL Profiler against the database while the call is happening, the value that I see in the trace is 4.033000183105469e+001

Where is all the extra garbage coming from (the 183105469)?

Why is it that when I pass in 40, or 40.25 there is nothing extra?

Is this just one of the weird side effects of using float? When I am writing something I normally use money or decimal or something else, so not that familiar with the float datatype.

like image 306
pfunk Avatar asked Mar 02 '23 05:03

pfunk


1 Answers

Yes, this is a weird, although well-known, side effect of using FLOAT.

In Microsoft SQL Server, you should use exact numeric datatypes such as NUMERIC, DECIMAL, MONEY or SMALLMONEY if you need exact numerics with scale.

Do not use FLOAT.

like image 96
Bill Karwin Avatar answered Mar 04 '23 01:03

Bill Karwin