Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count number of digits after a decimal place?

I am new to writing queries. I need a query that tells the number of digits after a decimal place.

Eg:

1001.00 = 0 digits after decimal
1001.01 = 2 digits after decimal
1001.010 = 2 digits after decimal

How can I do this?

like image 955
user3425746 Avatar asked Sep 02 '25 17:09

user3425746


1 Answers

ORACLE SOLUTION

This can be achieved by multiple ways one of them is below,

SELECT
length((1001.00) - trunc(1001.00)) - 1 as digits_after_decimal
FROM
dual;
SELECT
length((1001.01) - trunc(1001.01)) - 1 as digits_after_decimal
FROM
dual;    
 SELECT
length((1001.010) - trunc(1001.010)) - 1 as digits_after_decimal
FROM
dual;
like image 79
user12405446 Avatar answered Sep 04 '25 09:09

user12405446