mgr
mgr

Reputation: 436

SQL Server unexpected result of ROUND

The following statement:

SELECT ROUND(1.0 / 6.0, 6) AS RoundValue;

returns an unexpected (and wrong?) result:

0.166666

Only if I modify it like this:

SELECT ROUND(1.0 / 6.0000, 6) AS RoundValue;

it will return:

0.1666670

which has now the correct digit 7 at the end of the rounded part (but then adds a useless zero?)

This behaviour also happens when contents of columns of type NUMERIC(11,3) are used instead of float constants in the SELECT statement.

Upvotes: 1

Views: 59

Answers (1)

mgr
mgr

Reputation: 436

In the end I went for the pragmatic

ROUND(field1 / (field2 + 0.000))

Btw. in Oracle it works as expected.

Upvotes: 1

Related Questions