Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

I think this is probably just a precision issue - the 0.33 part of the number can't be represented exactly in binary - this is probably the closest that you can get to.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top