I'm trying to determine the best way to truncate or drop extra decimal places in SQL without rounding. For example:
declare @value decimal(18,2)
set @value = 123.456
This will auto round @Value to be 123.46....which in most cases is good. However, for this project I don't need that. Is there a simple way to truncate the decimals I don't need? I know I can use the left() function and convert back to a decimal...any other ways?
I know this question is really old but nobody used sub-strings to round. This as advantage the ability to round really long numbers (limit of your string in SQL server which is usually 8000 characters):
Another way is
ODBC TRUNCATE
function:LiveDemo
Output:
Remark:
I recommend using built-in
ROUND
function with 3rd parameter set to 1.Do you want the decimal or not?
If not, use
If you do it with 0 then do a round:
Please try to use this code for converting 3 decimal values after a point into 2 decimal places:
The output is 123.46