2

Let's have a look at the picture.

enter image description here

The result is different even though the expression is the same.

Why does this happen?

I have to follow excel result, what should I have do with sql server?

4
  • @MitchWheat Coz it's the same formula. Commented Mar 20, 2014 at 8:37
  • @MitchWheat Okay, but I have to find a solution to make it same as excel. That's my client's order no matter what. Commented Mar 20, 2014 at 8:38
  • round the results = 4,693,058 Commented Mar 20, 2014 at 8:39
  • @MitchWheat I need to get 4,693,057.99610 from sql server. Commented Mar 20, 2014 at 8:40

1 Answer 1

1

No matter whatever the software is 1+1 will always yeild 2 and if its not you should check you calculation again. see below

SELECT ((4972000.0000) * (1.0000 - 4.4000/100.0000)) 
         / ((1.0000 + ((36.0000/365.0000)) * (13.0000 / 100.0000)))


RESULT: 4693057.996104

To get the result on upto four decimal places Use ROUND() function.

SELECT ROUND(((4972000.0000) * (1.0000 - 4.4000/100.0000)) 
       / ((1.0000 + ((36.0000/365.0000)) * (13.0000 / 100.0000))), 4)

RESULT: 4693057.996100
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer. Could you explain why this kind of thinks happen?
My guess is that since you have only used two decimal places in your query sql server must have assumed it is DECIMAL(10,2) or NUMEIC(10,2) some numeric data type with 2 decimal places. but during calculation when a floating point value was yeild sql server did an implicit conversion to float datatype, which is an imaginary value. and will give you unexpected results.
@M.Ali: s/imaginary/imprecise/ ?
Imaginary is an imaginary/imprecise representation of an actual number. There are infinite number of "numbers" that cannot be presented in exact decimal form so we use an imaginary/imprecise number to represent the actual number. If this makes any sense :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.