[2022-06-29] Originally, this post was written back in July 2013 on Dewacorp's blog website. We consolidated all tech blogs into this place and we reformat the content to suit Dewapost's guidelines.
In SQL Server 2005, there is no inbuilt ROUNDUP and ROUNDDOWN function like on other SQL Server 2008 or 2012. To substitute this function is by adding/deducting .5 of the decimal point. For instance, the number is 12345.96124 and you want to 2 decimal points round up or round down is by adding/deducting 0.005
DECLARE @num1 FLOAT;
DECLARE @num2 FLOAT;
SET @num1 = 123.12345;
SET @num2 = 12345.96124;
SELECT @num1 AS ‘Number 1’,
@num2 AS ‘Number 2’,
CAST(@num2 AS INTEGER) AS ‘Integer’,
FLOOR(@num2) AS ‘Floor/round down’,
CEILING(@num2) AS ‘Ceiling/round up’,
ROUND(@num2+0.005,2) AS ‘Round-Up with 2 decimal point’,
ROUND(@num2-0.005,2) AS ‘Round Down with 2 decimal point’
Congratulation on reaching the end of this article. We hope that we have been able to shed some light on outlining the TSQL: the discovery.
We write this in such a way that this is not a fixed article. Like in this journey, we learn as we go and we re-write some parts so please keep pinging with this article.
We also would love to hear about how you deal with the situation and what problems you might be facing. Please feel free to leave us a comment below this article and let us know if you have any questions that we can answer! Thanks again!
If you want to boost your product and service to the wider web community, you can visit our Dewalist classified website – home to 31,000+ active users and 40,000+ active advertising so far. Check it out!
If you love this security article or any tech posts and you would like to receive an update of this article or our latest post, please sign up for the form below: