Decimal numbers of SQL number

I run a query and all my numbers are displayed up to 5 decimal places:

eg -

156713.55000 2103613.03000 2080.08000 

Is there a simple part of the code that I can add to my code, so the results of the Cost table are 2 decimal points?

+4
source share
2 answers

The following example will help you.

With rounding:

 select ROUND(55.4567, 2, 0) -- Returns 55.4600 select CAST(55.4567 as decimal(38, 2)) -- Returns 55.46 

Without rounding:

 select ROUND(55.4567, 2, 1) -- Returns 55.4500 select CAST(ROUND(55.4567, 2, 1) as decimal(38, 2)) -- Returns 55.45 

or

Use the Str() function. It takes three arguments (number, number of characters to display, and number of decimal places to display

  Select Str(12345.6789, 12, 3) 

displays: "12345.679" (3 spaces, 5 digits 12345, decimal point and three decimal digits (679). - rounded if necessary to trim

for a total of 12 characters, with 3 to the right of the decimal point.

+11
source

Just use the ROUND function:

 SELECT ROUND(column, 2) FROM Cost 

Or, to break down decimal and rounded values, use CAST :

 SELECT CAST(column as decimal(10, 2)) 
+5
source

Source: https://habr.com/ru/post/1412973/


All Articles