Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding - Is it possible to round down?

Status
Not open for further replies.

Risk

MIS
Feb 25, 2002
18
GB
Hi

We have a financial system based on a SQL Server 2005 database and there is a requirement in this system to round numbers down after 2 decimal places. So for example:

2500.627 - would need to be rounded down to 2500.62

However, At the moment, SQL Server rounds this to 2500.63 which is obviously the logical way of doing this.

Is there any way in SQL Server that this can be achieved? I have tried different things with no success apart from casting the number as a char then stripping it down before casting it back to a number, however, doing this over a large number of rows slows down the process considerably.

Thanks in Advance.

Risk
 
Code:
[COLOR=blue]declare[/color] @test [COLOR=blue]numeric[/color](10,5)
[COLOR=blue]SET[/color] @test = 2500.627 
[COLOR=blue]SELECT[/color] @test, [COLOR=#FF00FF]CAST[/color]([COLOR=#FF00FF]CAST[/color](@test*100 [COLOR=blue]as[/color] [COLOR=blue]int[/color])/100.0 [COLOR=blue]as[/color] [COLOR=blue]numeric[/color](10,2))

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Many thanks Borislav, that works a teat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top