I have following number in SQL Server 2008 : 5.4564556
I just want to get only 4564556 from 5.4564556
it would be better if i can get only 4 among 4564556 that is first digit of fractional part..
How can i do it?
Thanks
Use the CAST() function to convert an integer to a DECIMAL data type. This function takes an expression or a column name as the argument, followed by the keyword AS and the new data type. In our example, we converted an integer (12) to a decimal value (12.00).
For bigint use SELECT substr((2.938 % 1)::text,3)::bigint; , else use text result.
The Int() function returns the integer part of a number.
SQL Server ISNUMERIC() Function The ISNUMERIC() function tests whether an expression is numeric. This function returns 1 if the expression is numeric, otherwise it returns 0.
You can try in this way :
SELECT (5.4564556 % 1)
You can also use FLOOR():
SELECT Value - FLOOR(Value)
In your case:
5.4564556 - 5 = 0.4564556
in case of negative value you can use ABS
SELECT ABS(Value) - ABS(FLOOR(Value))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With