# Algorithm to adjust range / scale so it is "nicley" dividable by n

Hard to come up with a good title. I'm looking for an algorithm to adjust a range. Say I have 5.34 as min and 23.96 as max value. This gives it a range/difference of 18.62. I now want to divide this number by n (in my case always 5.5) and result of that division should be a "nice" or meaningful number to make a series from.

In this case we could enlarge the difference to 22 and get a series of 4,8,12,16,20,24 and set the limits to 4 and 26. The first problem obviously is the definition of a "nice number". A whole number fits that but also 0.25 or 0.5 would be good.

Having trouble coming up with an algorithm. Of course mod is involved but i above case 5-25 would be better fit as humans will look at this. How would I encode this "order of importance"? Scale can be arbitrary so maybe 100 is good or 100000. So a fixed list won't work either?

Take a look how plotting programs do this -- for example gnuplot. They also get odd values and need to find ways to display that with a meaningful scale.