Converting float to decimal in SQL Server 2008 -
i have view needs return type decimal columns stored float.
i can cast each column decimal follows:
, cast(field1 decimal) field1   the problem approach, decimal defaults 18,0, automatically rounds float columns 0. keep precision of 12 decimal places.
however, if this:
, cast(field1 decimal(12,12)) field1   i runtime error:
"arithmetic overflow error converting float data type numeric"   the float column defined length: 8 precision: 53 in table. can not modify table.
what's proper way cast decimal w/out losing decimal precision?
12, 12 means no digits before decimal separator: 12 digits in total, 12 of them being after period.
use more appropriate range, say:
declare @var float = 100 select  cast(@var decimal(20,12))   which gives 8 digits before separator, or adjust needed.
Comments
Post a Comment