I am trying to get the number with the decimal values.
Here is the following example:
I have two numbers: 621
which should be divided by 7
and result should be shown in the form of number with at least 3 digits decimal values. Accordingly the result should be 88.714
.
My Try1:
SELECT CAST(621/7 as DECIMAL(5,3));
Getting result is 88.000
.
Try 2:
SELECT CONVERT(DECIMAL(5,3), 621/7);
Getting result is 88.000
.
You have to convert before you divide in order to avoid integer division. Easiest way is:
cast(621*1.0/7 as Decimal(5,3))
In your examples, the division is happening first, then the convert/cast is being applied to that result.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments