Step 1:- Dividing an integer value by an integer value
If you are dividing an integer value by an integer
value, the result will also be an integer.
Select 23 / 5
Results
-----------
4
(1 row(s) affected)
Step 2:- Dividing an integer value by a decimal value
If you are dividing an integer value by a decimal value,
the result will be decimal.
Select 23 / 5.0
Results
---------------------------------------
4.600000
(1 row(s) affected)
If you need only two digits after decimal you can use
cast or convert.
Using cast
Select cast (23 / 5.0 as decimal (18, 2))
Results
---------------------------------------
4.60
(1 row(s) affected)
Using convert
Select convert (decimal (18, 2), 23 / 5.0)
Results
---------------------------------------
4.60
(1 row(s) affected)
No comments:
Post a Comment