Discussion:
Rounding problem
(too old to reply)
d***@googlemail.com
2013-07-29 13:02:46 UTC
Permalink
Unless anyone can give me a realistic example of why you would need to divide one monetary value by another I have to disagree that this is any kind of issue whatsoever.
We have discovered a interesting rounding "feature" that we would like some
input on.
Check the following set of statements. As it appears T-SQL is very picky
with regards to the syntax required for producing correct results when doing
math on money type fields. As with all these things, doing it right when you
are aware of the problem is usually not a problem..... until some unlucky
guy forgets.
***********
@pab money,
@owf money,
@paf1 money,
@paf2 money
@pab = 4023306.45,
@owf = 89087.50
-- Expected result : 10058.27
Wrong Correct
--------------------- ---------------------
10057.9800 10058.2700
******************
I believe this behaviour is very dangerous. And in this occation it is in
fact about money, large amounts of money. From other langauages I am used to
including a decimal type constant in the expression to force usage of
correct internal storage types during calculation, but in T-SQL it appears
you have to repeat this trick for each element of the expression.
Do we just have to live with this or have we missed out on something here??
TIA,
Erlend
m***@gmail.com
2013-10-14 15:01:10 UTC
Permalink
How about I would like to buy $1000.00 worth of shares at a price of $36.00 each.
How many do I actually buy?
$1000/$36
Post by d***@googlemail.com
Unless anyone can give me a realistic example of why you would need to divide one monetary value by another I have to disagree that this is any kind of issue whatsoever.
We have discovered a interesting rounding "feature" that we would like some
input on.
Check the following set of statements. As it appears T-SQL is very picky
with regards to the syntax required for producing correct results when doing
math on money type fields. As with all these things, doing it right when you
are aware of the problem is usually not a problem..... until some unlucky
guy forgets.
***********
@pab money,
@owf money,
@paf1 money,
@paf2 money
@pab = 4023306.45,
@owf = 89087.50
-- Expected result : 10058.27
Wrong Correct
--------------------- ---------------------
10057.9800 10058.2700
******************
I believe this behaviour is very dangerous. And in this occation it is in
fact about money, large amounts of money. From other langauages I am used to
including a decimal type constant in the expression to force usage of
correct internal storage types during calculation, but in T-SQL it appears
you have to repeat this trick for each element of the expression.
Do we just have to live with this or have we missed out on something here??
TIA,
Erlend
DaveB...@Gmail.com
2014-10-23 14:24:04 UTC
Permalink
Post by m***@gmail.com
How about I would like to buy $1000.00 worth of shares at a price of $36.00 each.
How many do I actually buy?
$1000/$36
Oh I see - and the answer is $27.7778, right? Wrong! Go try to by $27.7778 shares. No, the answer is 27.77777777... shares. It's unitless.

I think Dean's question should have been "Why would you expect Money divided by Money to be Money?"

Sql Server's bug is that it treats the results of Money/Money (and Money*Money) as Money. This should have been Decimal (ie unitless).
Loading...