title: Calculating steps from a min/max scenario, and steps should be nice numbers c#
body: <p>Im working on a heatmap where i have to display zones on a map filled by a color calculated by a range of values.</p>
  
  <p>I got the zone color part figgured out, but i also have to display 5 steps, each step providing a color and a value, explaining what the color means.</p>
  
  <p>So, lets say i have a minimum value of 2654 and a maximum value of 6947.
  This provides me with a range of 5 numbers, which are:</p>
  
  <pre><code>2654
  3727,25
  4800,5
  5873,75
  6947
  </code></pre>
  
  <p>Now what i want is to display these values as nice intervals, like this:</p>
  
  <p>0 - 3000</p>
  
  <p>3000 - 4000 </p>
  
  <p>4000 - 5000</p>
  
  <p>5000 - 6000 </p>
  
  <p>&gt; 6000</p>
  
  <p>These values are ofcourse dynamic.
  So it could be either huge numbers or small numbers.
  Is there any way to do this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>@roberto-carlos i tried your example below:</p>
  
  <pre><code>  var min = 900;
    var max = 12541;
    var steps = 5;
  
    var range = Enumerable.Range(0, steps).Select(i =&gt; min + (max - min) * ((double)i / (steps - 1)));
  
    foreach (var d in range)
    {
      var power = Math.Floor(Math.Log10(d));
      var inf = d - d % Math.Pow(10, power);
      var sup = d + (Math.Pow(10, power) - d % Math.Pow(10, power));
  
      if (d == min)
      {
        Console.WriteLine("0-" + sup);
      }
      else if (d == max)
      {
        Console.WriteLine("&gt;" + sup);
      }
      else
      {
        Console.WriteLine(inf + "-" + sup);
      }
    }
  </code></pre>
  
  <p>However, this provides me with a result like this:</p>
  
  <pre><code>  0-1000
    3000-4000
    6000-7000
    9000-10000
    &gt;20000
  </code></pre>
  
  <p>Is there any way to make the intervals "stick together" numberwise?</p>