sql - Round value only if it is greater than 5 -


i'm not sure duplicate question.

i need round value if succeeding value greater 5.

for example:

if have 123.4575, rounded value should 123.457.

if have 123.4576, rounded value should 123.458.

but default round not working i'm expecting. see below query,

select cast(round(123.4575, 3) decimal(18,3)) 

result:


123.458 (where needs 123.457)

i need 3 decimal points.

i prefer suggest me in-built functions rather writing functions on own.

thanks.

this has been asked (many times). 5 rounded sql server. if not want write own routine @ minh's answer here. shows neat trick achieve want using case statement , floor.

also easy alternative subtract 1 number first @ precision 1 greater rounding, thus:

select cast(round(123.4575 - 0.00001, 3) decimal(18,3))  

gives 123.457, whilst

select cast(round(123.4576 - 0.00001, 3) decimal(18,3))  

gives 123.458


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -