title: Javascript convert HSB/HSV color to RGB accurately
body: <p>I need to accurately convert HSB to RGB but I am not sure how to get around the problem of turning decimals into whole numbers without rounding. This is the current function I have out of a colorpicker library:</p>
  
  <pre><code>HSBToRGB = function (hsb) {
  
      var rgb = { };
      var h = Math.round(hsb.h);
      var s = Math.round(hsb.s * 255 / 100);
      var v = Math.round(hsb.b * 255 / 100);
  
          if (s == 0) {
  
          rgb.r = rgb.g = rgb.b = v;
          } else {
          var t1 = v;
          var t2 = (255 - s) * v / 255;
          var t3 = (t1 - t2) * (h % 60) / 60;
  
              if (h == 360) h = 0;
  
                  if (h &lt; 60) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3 }
                  else if (h &lt; 120) { rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3 }
                  else if (h &lt; 180) { rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3 }
                  else if (h &lt; 240) { rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3 }
                  else if (h &lt; 300) { rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3 }
                  else if (h &lt; 360) { rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3 }
                  else { rgb.r = 0; rgb.g = 0; rgb.b = 0 }
          }
  
      return { r: Math.round(rgb.r), g: Math.round(rgb.g), b: Math.round(rgb.b) };
  </code></pre>
  
  <p>As you can see the inaccuracy in this function comes from the Math.round</p>