Quantcast
Channel: DataType question.
Viewing all articles
Browse latest Browse all 6

DataType question.

$
0
0
This is basically a rounding issue, and it's up to you to decide what is right or wrong.
There are no 'correct' overriding rule that says how things always should be rounded.

IIRC, SQL Server by default rounds up.

If we look at 64.45 * 0.90 the result is 58.005
So, by default, you'll get 58.01, since SQL Server will round up, and .005 becomes .01 with two decimals.

If this is correct or not, needs to be decided by the business rules.

When we say ROUND(64.45 * 0.90, 1) then the expression is still rounded, but to the precision of one decimal.
We could also choose to truncate the result from two decimals precision,

It looks something like this;

SELECT ROUND(58.005, 1)     = 58.000 (since we round to just one decimal)
SELECT ROUND(58.005, 2)     = 58.010 (with two decimals .005 gets rounded up to 0.10)
SELECT ROUND(58.005, 2, 1) = 58.000 (still we want to use two significant decimals, but not rounded, only truncated. Som the trailing 5 is just 'cut off')

You can find more info about ROUND and the different options and behaviours here
http://msdn.microsoft.com/en-us/library/ms175003.aspx

=;o)
/Kenneth

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>