HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Rounding Down with ROUND() function

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
withfunctiondownroundrounding

Problem

I am wanting to round down these numbers, and I have tried several different ROUND() functions but can not get it exactly right. Take this sample DDL

Create Table #Fun
(
  value1 float
)

Insert Into #Fun Values
(1002313), (1888222), (1666222), (1222333)

Select
ROUND([value1], -5) As Rounded
FROM #Fun

Drop Table #Fun


In the below the left column is what SQL produces and the right is what I want it to be. What must be altered in SQL in order to provide the output I am requesting?

1000000 = is fine
1900000 = 2000000
1700000 = 1500000
1200000 = 1000000

Solution

It actually looks like you're trying to get the nearest 500000.

Look here: https://stackoverflow.com/questions/1702080/round-to-nearest-5-in-sql-server

In your case, use ROUND(value1/500000.0,0)*500000

Context

StackExchange Database Administrators Q#150165, answer score: 4

Revisions (0)

No revisions yet.