# Help with Round function RSS

## 11 replies

Last post Dec 13, 2012 03:26 PM by StrangerMike

Contributor

2708 Points

1733 Posts

### Help with Round function

Hello,

I am calculating a percentage and I would like the result to round up to nearest whole number:

This is the line I use for calculating the percentage:

Cast(Taba.Vistor_Cnt - tabb.Vistor_Cnt as numeric (6,0)) / cast(taba.Vistor_Cnt as numeric (6,0)) * 100 as Pct

The results come back as:  25.0000000 or  -166.0000000 or 10.2230000.

I would like results to look like 25, -166, or 10 (or perhaps 10.2) not decided if we need to carry the decimcal.

Can you help. Thanks

Thanks

Participant

1278 Points

195 Posts

### Re: Help with Round function

Try:

```Cast( Cast(Taba.Vistor_Cnt - tabb.Vistor_Cnt as numeric (6,0)) /
cast(taba.Vistor_Cnt as numeric (6,0)) * 100
as numeric (6,0)) as Pct```

or

```Cast( Cast(Taba.Vistor_Cnt - tabb.Vistor_Cnt as numeric (6,0)) /
cast(taba.Vistor_Cnt as numeric (6,0)) * 100
as numeric (6,1)) as Pct```

Hope this helps.

Contributor

2708 Points

1733 Posts

### Re: Help with Round function

Thanks,  niether compiled clean. Errors:

Incorrect syntax near the keyword 'as'.

Thanks

Participant

1278 Points

195 Posts

### Re: Help with Round function

Try the following script in SQL Server Management Studio:

```declare @ValA numeric(6, 0);
declare @ValB numeric(6, 0);

set @ValA = 12;
set @ValB = 7;

select CAST( Cast(@ValA - @ValB as numeric (6,0)) /
cast(@ValA as numeric (6,0)) * 100
as numeric (6, 1)) as Pct```

Hope this helps.

All-Star

31515 Points

6433 Posts

### Re: Help with Round function

`convert(int,Cast(Taba.Vistor_Cnt - tabb.Vistor_Cnt as numeric (6,0)) / cast(taba.Vistor_Cnt as numeric (6,0)) * 100) as Pct`

or

```convert(decimal(10,1),Cast(Taba.Vistor_Cnt - tabb.Vistor_Cnt as numeric (6,0)) / cast(taba.Vistor_Cnt as numeric (6,0)) * 100) as Pct
```

Programming to simplify, dont look for hard way
• Edited by oned_gk on Dec 13, 2012 12:04 AM
• Marked as answer by StrangerMike on Dec 13, 2012 03:24 PM

Member

271 Points

76 Posts

### Re: Help with Round function

`convert(int,convert(numeric(6,0),Taba.Vistor_Cnt - tabb.Vistor_Cnt ) / convert(numeric(6,0),taba.Vistor_Cnt ) * 100) as Pct`
` `
`This will work. `

All-Star

31515 Points

6433 Posts

### Re: Help with Round function

`convert(int,(Taba.Vistor_Cnt - tabb.Vistor_Cnt / taba.Vistor_Cnt) * 100) as Pctor`

Programming to simplify, dont look for hard way

Contributor

2708 Points

1733 Posts

Thanks:

Thanks

Contributor

2708 Points

1733 Posts

thanks

Thanks

Contributor

2708 Points

1733 Posts