SQL Server Select round function of a number [closed]

wkyowqbh  于 2023-06-04  发布在  其他
关注(0)|答案(1)|浏览(207)

Closed. This question needs details or clarity . It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post .

Closed 2 days ago.
Improve this question

In SQL Server, how can I transform the value 8796842.09999999 into 8796842.0500 ?

I tried the round function, but it doesn't work

jckbn6z7

jckbn6z71#

You can use the expression which yields 8796842.05 for the given value:

ROUND(20 * 8796842.09999999, 0, 1)/20

The second argument of the ROUND function specifies the number of decimal places. Since we handle the decimal places by multiplying 20 already, we set this parameter to 0.

The third argument means round if 0, and truncate otherwise.

Multiplying by 20 before truncating and dividing by 20 afterwards truncates at every 0.05 (1/20) step.

See: ROUND (Transact-SQL)

相关问题