SQL Server round up to 0.5 multiple

s4chpxco  于 2023-02-28  发布在  SQL Server
关注(0)|答案(2)|浏览(201)

How can I round up the values to the multiples of 0.5 in SQL Server.

I tried using CEILING , ROUND and CASE functions.

vjhs03f7

vjhs03f71#

ROUND(<value> * 2, 0) / 2

So, you multiply the input value by 2, rounding it to the nearest integer, then dividing it by 2 to get to the nearest multiple of 0.5

lmvvr0a8

lmvvr0a82#

To round up to the nearest 0.5 double, then take the ceiling then divide by 2.

declare @n decimal(12,4) = 12.0

select ceiling(2.0*@n)/2.0

相关问题