# 00 after decimal in sqlRSS

## 3 replies

Last post Mar 28, 2018 12:49 PM by Prince Srivastava

• binustrat

Member

16 Points

44 Posts

### 00 after decimal in sql

Hi,

I had 4 integer and one decimal colum in sql table

i try to add four int column and divided by 4 and save in decimal colum. but when save output in decimal colum getting after decimal 00 always?

col1, col2, col3, col4, col5
60, 100, 0 30 47.00 expected answer (60+100+0+30)/4 is 47.5

• wmec

Contributor

6358 Points

5650 Posts

### Re: 00 after decimal in sql

Try

```select cast((60+100+0+30) as decimal(10,2))/4
```

Many Thanks & Best Regards,
HuaMin Chen
• mshoaiblibra

Contributor

2832 Points

767 Posts

### Re: 00 after decimal in sql

#### binustrat

col1, col2, col3, col4, col5
60, 100, 0 30 47.00 expected answer (60+100+0+30)/4 is 47.5

As per you needs check following query. You can use this query according your requirement

```DECLARE @col1 AS INT = 60;
DECLARE @col2 AS INT = 100;
DECLARE @col3 AS INT = 0;
DECLARE @col4 AS INT = 30;

select cast(cast((@col1+@col2+@col3+@col4) as decimal(10,2))/4 as numeric(36,2)) AS col5;```

.

Please mark the replies as if they help or unmark if not.

M Shoaib Waheed
MCSD & MCPD [Web Development 4.0]
http://shoaib.pk
• Prince Sriva...

Participant

1822 Points

562 Posts

### Re: 00 after decimal in sql

Mar 28, 2018 12:49 PM|Prince Srivastava|LINK

Hi You can use below query

select FORMAT(cast((60+100+0+30) as decimal(10,2))/4,'N2')