Here's one way:
- declare
@input table(fl float)- --
- insert
@input(fl)- select
123456789000 union all- select
12345678900 union all- select
1234567890 union all- select
123456789 union all- select
12345.6789 union all- select
1234.56789 union all- select
123.456789 union all- select
12.3456789 union all- select
1.23456789 union all- select
0.123456789 union all- select
0.0123456789 union all- select
0.00123456789 union all- select
0.000123456789 union all- select
0.0000123456789
--declare @sigfigs tinyint
select @sigfigs = 0
--while @sigfigs < 11
begin--select fl float_value, @sigfigs sigfigs
,floor(fl/power(cast(10 as float),floor(log10(fl))+1-@sigfigs))
*power(cast(10 as float),floor(log10(fl))+1-@sigfigs) new_value
from @input
--select @sigfigs = @sigfigs + 1
--end
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant