VAAA VAAA - 5 months ago 7x
SQL Question

SQL get decimal with only 2 places with no round

I have a query (

SQL Server
) that returns a decimal. I only need 2 decimals without rounding:

enter image description here

In the example above I would need to get: 3381.57

Any clue?


You could accomplish this via the ROUND() function using the length and precision parameters to truncate your value instead of actually rounding it :

SELECT ROUND(3381.5786, 2, 1)

The second parameter of 2 indicates that the value will be rounded to two decimal places and the third precision parameter will indicate if actual rounding or truncation is performed (non-zero values will truncate instead of round).


enter image description here

You can see an interactive example of this in action here.