Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Function Parameter from Float to Numeric

Author  Topic 

jandh98
Starting Member

10 Posts

Posted - 2014-07-15 : 10:32:58
I am working on a problem that is already deployed that has to do with rounding. I have tracked the problem down to a Function parameter that is a float. When I change that parameter to a numeric field, the rounding problem corrects itself. This Funcation is being used in several other reports we use and my testing has shown good results in making the change.

But before I proceeded, I wanted to ask what the experts think about any ramifications of changing this parameter from a float to a numeric field. I guess I feel like the fix is too easy. :)

Thx!
Heather

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-07-15 : 10:48:33
For the most part, the only impact is the change from approximate representation (FLOAT) to exact numeric (NUMERIC or DECIMAL), and the associated changes in precision of calculations. If you didn't specify a precision and scale for the numeric data type, you should. Otherwise you are effectively converting the floating point number to integers.

There can be some other side effects, for example, if you are trying to convert a character string, you may not be able to convert some strings to numeric that you can convert to float. for example, the second select will throw an error
DECLARE @x VARCHAR(32) = '17E0';
SELECT CAST(@x AS FLOAT);
SELECT CAST(@x AS NUMERIC(10,2));
Go to Top of Page
   

- Advertisement -