In this article, I will explain how to Convert Decimal Numbers to Money with cents / without cents in SQL.
You might also like to read How to convert Gregorian date to Hijri date SQL Server 2012
Convert Decimal to Money SQL
I have a decimal number like 71567536.100000, I need to convert it to money format
- with cents to be like this 71,567,536.10 ر.س
- without cents to be like this 71,567,536 ر.س
Convert Decimal to Money with Cents in SQL
You can use one of the below quires
SELECT STUFF( convert(varchar, convert(money,71567536.100000),1) , 1, 0,'.') + N' ر.س ' as 'Budget'
SELECT convert(varchar(100), cast(71567536.100000 as money), 1)+ N' ر.س ' as 'Budget'
Output
Convert Decimal To Money Without Cents In SQL Server
You can use one of the below quires
SELECT parsename( convert(varchar(100), cast(71567536.100000 as money), 1),2) + N' ر.س ' as 'Budget'
SELECT replace( convert(varchar, cast(floor(71567536.100000) as money),1), '.00', '') + N' ر.س ' as 'Budget'
Note: The second statement faster than the first with 21 NS.
Output
Conclusion
In conclusion, we have learned how to Convert Decimal to Money SQL Server.
Applies To
- SQL Server 2016
- SQL Server 2012