Sql Calculation Not Showing In Correct Format
Solution 1:
Your declaration is wrong:
declare@adecimal(10,0)
declare@bdecimal(10,0)
You have specified the length, however not the number of decimals, which is done by using the second value.
Solution 2:
700 is the correct result.
Please check again!
((100 - 2) / 14) * 100 = 700
You calculated that
100 - 2 / 14 * 100 = 85,...
You want to use this sql query.
set@a = 100 - 2.0 / 14 * 100Solution 3:
Add a .0 to the end of your last line, since if you use all integers SQL will implicitly cast the result as an int.
set@a = ((100 - 2) / 14) * 100.0Solution 4:
change your declarations to include decimal places:
declare@adecimal(10,5)
declare@bdecimal(10,5)
set@a=100-2set@a=@a/14set@a=@a*100set@a= ((100-2) /14) *100select@aSince your declaration is set to 10,0 then you will get no decimal places.
if you want the answer to be 85.714... then you need to change your SQL to:
declare@adecimal(10,5)
set@a=100.0-2.0set@a=@a/14.0set@a=@a*100.0set@a=100.0- ((2.0/14.0) *100.0)
select@aTo get the result you are looking for you need to add a . to the other values (2, 14, etc) and you will get the value you want, you also need to make sure that your parentheses are in the correct location.
Results - 85.71430
Post a Comment for "Sql Calculation Not Showing In Correct Format"