Select only the fractional part of the value of the number

How to select only part of the value of the number to the right of the decimal point?

So for example:

SELECT ____(10.1234) AS mynumber; 

Where is the result:

 .1234 (or 1234) 
+8
decimal mysql numbers
source share
3 answers

The MOD> function should work:

 SELECT MOD(10.1234, 1); -- -> 0.1234 
+14
source share

Just subtract the integer part:

 select mynumber - truncate(mynumber,0) from mytable; 
+2
source share

You can also use below ...

 select substring_index(field1,'.',1), substring_index(field1,'.',-1) from table1; 

Output example

 mysql> select substring_index(120.45,'.',1), substring_index(120.45,'.',-1) ; +-------------------------------+--------------------------------+ | substring_index(120.45,'.',1) | substring_index(120.45,'.',-1) | +-------------------------------+--------------------------------+ | 120 | 45 | +-------------------------------+--------------------------------+ 1 row in set (0.00 sec) 
+2
source share

All Articles