September 4, 2014 at 11:12 pm
Hi Everyone,
I don't understand why I am getting all zeros after the decimal point below.
I have two main questions -
1). Why are there so many places after the decimal point?
2). Why am I seeing nothing but zeros (I expected 14.46888137723487)?
Any help will be greatly appreciated.
Kind Regards,
David
September 4, 2014 at 11:24 pm
U have to specify the decimal places
Runt the below ...U will get the expected result
declare @dividend decimal(12,5),@divisor decimal(12,5)
set @dividend='105.12345425'
set @divisor='7.2654859425'
select @dividend/@divisor
September 5, 2014 at 12:04 am
Hi Indu,
Thank you for your response. Initially when I tried to specify the decimal values parameters, e.g.: DECLARE @dividend decimal(10,3), I was met with 'red underlines' in SSMS. However something unrelated was probably happening.
At any rate now that I am able to correctly setup the variables I am able to lead into the real issue that I am facing. I really want to limit the decimal 'fidelity' to two decimal places after a division operation, however no matter what I do I can't seem to achieve the desired outcomes.
What is happening above?
Why after declaring decimal(10,3) am I seeing so many decimal places in my result?
Why is a CAST statement that specifically tells both the dividend and the divisor to be two decimal places being ignored?
How can I get a result like 14.59?
Adding a CAST to the entire line, e.g.: CAST(@dividend / @divisor AS decimal(15,2)), causes an 'Incorrect Syntax' error!
Any further help or suggestions will be greatly appreciated.
Kind Regards,
David
September 5, 2014 at 12:08 am
David,
you have just specified the datatypes for the inputs.
there are many decimals in the result ,as u haven't restricted the decimal places for output
do the below
declare @dividend decimal(12,5),@divisor decimal(12,5)
declare @output decimal(12,2)
set @dividend='105.12345425'
set @divisor='7.2654859425'
set @output = @dividend/@divisor
select @output
September 5, 2014 at 12:18 am
Hi Indu,
This works great for static data held in variables, however I want to achieve the same outcome using actual data contained in tables. Can you please explain how to do this 'on the fly', that is without using variables?
Kind Regards,
David
September 5, 2014 at 12:21 am
You've already defined the inputs. Cast the answer, not the parts of the formula.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 5, 2014 at 12:25 am
david.dartnell (9/5/2014)
Hi Indu,Thank you for your response. Initially when I tried to specify the decimal values parameters, e.g.: DECLARE @dividend decimal(10,3), I was met with 'red underlines' in SSMS. However something unrelated was probably happening.
At any rate now that I am able to correctly setup the variables I am able to lead into the real issue that I am facing. I really want to limit the decimal 'fidelity' to two decimal places after a division operation, however no matter what I do I can't seem to achieve the desired outcomes.
What is happening above?
Why after declaring decimal(10,3) am I seeing so many decimal places in my result?
Why is a CAST statement that specifically tells both the dividend and the divisor to be two decimal places being ignored?
How can I get a result like 14.59?
Adding a CAST to the entire line, e.g.: CAST(@dividend / @divisor AS decimal(15,2)), causes an 'Incorrect Syntax' error!
Any further help or suggestions will be greatly appreciated.
Kind Regards,
David
BRACES ARE MISSING
Below will work
CAST((@dividend / @divisor) AS decimal(15,2))
September 5, 2014 at 12:44 am
BRACES ARE MISSING IN UR QUERY
Below will work
CAST((@dividend / @divisor) AS decimal(15,2))
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply