Wednesday, December 19, 2007

return the number of digits after the decimal point

select greatest(length(abs(x - trunc(x))) - 2, 0) from (values (12345.12345::numeric), (1234.1234::numeric), (1234.123::numeric), (-1234.123::numeric), (1::numeric), (10::numeric)) as t(x);



select length(regexp_replace(x::numeric::text,'^.*\\.',''))
from
(values (12345.12345::numeric), (1234.1234::numeric), (-1234.123::numeric)) as t(x);

0 Comments:

Post a Comment

<< Home