Comments on: How to round to the nearest whole multiple or fraction in SQL http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Beverley M http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/#comment-17630 Beverley M Wed, 20 Jan 2010 21:53:44 +0000 http://www.xaprb.com/blog/?p=1214#comment-17630 Ah, perfect, thanks! I have a line graph that displays millions of dollars. I wanted to set the Y axis to the farthest multiple of \$50m over and under the current day’s value. This did the trick niceley, and now I don’t have to manually update and hard code the axis min & max every few months.

]]>
By: Generating numbers out of seemingly thin air | code.openark.org http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/#comment-16909 Generating numbers out of seemingly thin air | code.openark.org Tue, 01 Sep 2009 06:39:13 +0000 http://www.xaprb.com/blog/?p=1214#comment-16909 [...] other day, Baron Schwartz posted How to round to the nearest whole multiple or fraction in SQL. In an offhand way, he generated some random numbers using the mysql.help_topic table. I then [...]

]]>
By: n http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/#comment-16804 n Sat, 22 Aug 2009 01:37:44 +0000 http://www.xaprb.com/blog/?p=1214#comment-16804 hi
no problem either

i ran

update table 1
set minnumber=minnumber -5 where min(number)like ‘%%%2.5%%%’
update table 1
set minnumber=minnumber -5 where min(number)like ‘%%%7.5%%%’

so whereas before any number ending like %%%2.5%%% was getting rounded up to 6005 when i wanted it as 6000 and any number ending up like ‘%%%7.5%%%’was getting rounded up to 6010 when i wanted it as 6005 now with the update function everything is corrected.
(isn’t this a nice way to get around the round up problem so simple yet logical)
i know it an extra step but it works and that should count even for a newbielike me (second week learning sql:))

beats spending the next few days trying to work out a formula im sure there is one but time dictates if it works move on.

]]>
By: n http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/#comment-16798 n Fri, 21 Aug 2009 15:24:42 +0000 http://www.xaprb.com/blog/?p=1214#comment-16798 hi found problem if the number equals 6007.5000 or 6002.5000
will always round up ,i used

minnumber= CAST (cast ((round(min(number) *20000,-5)) as decimal )/20000 AS NUMERIC (8,4))

this sets the number intervals in 5.0 point increments and it always rounds up if number is at ‘%%%2.5%%%’ and ‘%%%7.5%%%’(ie, midpoint of the 5 point intervals)

how can i set these two numbers so they show as 6000.0000 and 6005.000 respectively whilst not changing the rest
any ideas

]]>
By: n http://www.xaprb.com/blog/2009/08/09/how-to-round-to-the-nearest-whole-multiple-or-fraction-in-sql/#comment-16781 n Wed, 19 Aug 2009 23:39:06 +0000 http://www.xaprb.com/blog/?p=1214#comment-16781 sixes and sevens no more i just multiplied the number far out then round((),-5) and divide by same number so now i get the numbers from 6003 to 6007 shown as 6005 and 6008-6112 shown as 6010, 6113 to 6117 as 6015 and so on….

:)

]]>