How to convert a value with 2 places after decimal to 6 places after decimal in MSSQL?
Eg : 350.00 to 350.000000
SELECT ROUND(350.00, 6) AS RoundValue;
Returns 350.00
Expected output is 350.000000
Should a function other than round()
be used?
Thank you in advance.
1条答案
按热度按时间r7xajy2e1#
You do not. There are no trailing zeroes on a NUMBER - only on a STRING.
Means: As long as you have the value in a number variable (in any programming language btw.) it will not record how many irrelevant zeroes there are - if you want to see them, you do that on the output and format the string.
SQL Server supports this - you need to convert the number into a string with the proper formatting.
This is not ROUND, this is FORMAT, in SQL Server. The output of that is not a number, by type, but a string - otherwise it would not maintain formatting. Bad for maths, good for output.