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 to Nearest Half, etc. 1

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
US
Hello List!

I have a question...

I want to round a number to the nearest half --

I tried this:
Code:
select addID,
  addLat, dec(round(addLat * 2, 0)/2,11,1) as Nearest_Half
from Addresses

But, am getting an error msg:

Msg 195, Level 15, State 10, Line 2
'dec' is not a recognized built-in function name.


I found this explanation online of how to accomplish this:
1. Multiply the number by the reciprocal of the fraction.
2. Round to a whole number.
3. Divide by the reciprocal of the fraction.


So, my number is 42.656621, and I want the nearest half --> 42.500000.

Need to do this for the nearest quarter, twentieth, and hundredth as well, but first want to get the half down and work up from there!

Which I'm trying to do, but the 'dec' part is giving me some problems...Any thoughts or ideas?

Thanks much! Your expertise and time are very much appreciated!!
-jiggyg
 
Code:
select addID,
  addLat, [!]Convert(Decimal(11,1), [/!]round(addLat * 2, 0)/2[!])[/!] as Nearest_Half
from Addresses

Just out of curiosity, what does rounding a latitude to the nearest .5 do for you? I mean.... what are you really trying to accomplish?



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
The reason I ask is because I have a bit of experience with Latitude and Longitude calculations. If you want to incorporate some sort of proximity search, there's a better way than rounding values.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks, gmmastros!

I'm going to use these values for a new Latitude depending on the zoom level used by the user; if they zoom to level 5, only show the address at the nearest half Latitude, level 3, quarter Latitude, etc. -- we have too many points on the map and are trying to clean them up a bit.

Thanks again!
-jiggyg
 
If I understand correctly...

You want to display just 1 icon on the map (at the nearest half latitude) if the user is zoomed to level 5. So, theoretically, there could be multiple items represented by each icon (at that zoom level). Is that right?



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi gmmastros,

Yes; for example, Denver CO, has 4 locations --

At:
zoom level 3, I only want to show 1 icon (because they're all on top of each other!);
zoom level 5, still probably only 1 icon;
zoom level 6, 1, 2, or 3 icons, depending on how close they are;
zoom level 8, probably 2 or 3, depending on locations;
zoom level 10, probably all 3;
zoom level 12, show all 3.

Did that make sense?
Thanks!
-jiggyg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top