对于您的significance
的具体定义,我认为没有更好的方法。甚至更多您提出的解决方案是不正确的,它会被误认为123000000.00
甚至123456.7
。所以,你需要删除.
和尾随零:
with data (a) as
(
select 12345678 from dual union all
select 12345678.0 from dual union all
select 12345678.1 from dual union all
select 1234567 from dual union all
select 123456789.234 from dual union all
select 0.123456789 from dual
)
select
*
from data
where
length(rtrim(replace(to_char(abs(a)), '.'), '0')) >= 8
不幸的是我没有Oracle数据库进行测试。但我有MS SQL Server的,所以我把它移植和测试:
with data (a) as
(
select 12345678 union all
select 12345678.0 union all
select 12345678.1 union all
select 1234567 union all
select 123456789.234 union all
select 0.123456789
)
select
*
from data
where
len(rtrim(replace(replace(str(abs(a)), '.', ''), '0', ' '))) >= 8
所不同的只是在甲骨文=> SQL服务器:
rtrim('..', '0')
=>rtrim(replace('...', '0', ' '))
,
length
=>len
我不认为有办法解决这个问题,因为没有办法检查一个数字并确定有多少数字实际上是重要的。当然,例如,'123000000.000'。为什么*那无效,但是'123000001.000'或'122999999.000'会有效?您不能自动确定尾随“0”(小数点前)不重要。 –
浮点值以二进制形式存储。从字符表示转换到字符表达时,某些舍入问题可能会带来非常意想不到的结果。什么看起来像几个小数浮点数,被存储为类似的东西 - 但四舍五入,并返回许多小数。 – jarlh