Sto usando SQL Server 2008 R2.
Devo raggiungere il seguente arrotondamento. Se la prima cifra dopo il punto decimale è 0 Dovrebbe arrotondare al lato inferiore, se superiore o uguale a 1, dovrebbe arrotondare al lato superiore, dati di esempio:
3.09 ---> 3
3.1 ---> 4
0 ---> 0
3.005 ---> 3
668.15 ---> 669
Quale sarebbe il modo più semplice per raggiungerlo?
Ho provato a fare qualcosa del genere:
SELECT CEILING(3.09) -- this is incorrect, returning 4 instead of 3
SELECT ROUND(3.09,0) -- with 3.09 is ok, but if I"m trying to round 3.1 It still returning 3.00 instead of 4
Forse in qualche modo potrei combinarlo? O ho bisogno di altre funzioni?
risposte:
4 per risposta № 1SELECT ROUND(val + 0.4, 0) rnd_val
FROM (
VALUES
(3.09),
(3.1 ),
(0),
(3.005),
(668.15)
)v (val)