title: Javascript prototype function: decimal time value to a time string
body: <p>On a project I'm currently working on in JavaScript, I'm using decimal formats so it's easier to calculate with rather than using an hour/minute format in strings (calendar related project). To display the time on the user's screen though, the timecode has to be shown as hh:mm.</p>
  
  <p>I thought it would be great to use a String prototype function for this as it would allow me to use code like:</p>
  
  <pre><code>var time = 8.75;
  document.write("Meeting at "+time.toTime()); // writes: Meeting at 8:45
  </code></pre>
  
  <p>So far, I've got that almost working, using:</p>
  
  <pre><code>String.prototype.toTime = function(){
      var hrs = this.toString().slice(0,this.indexOf("."));
      var min = Math.round(this.toString().slice(this.indexOf("."))/100*60);
      min = min&lt;10 ? "0"+min : min.toString();
      return hrs+":"+min;
  }
  </code></pre>
  
  <p>The problem, though, is that this will only work if the variable <code>time</code> is a string. Otherwise it will give an undefined error.</p>
  
  <p>Would there be any way of applying the prototype to a different object in JavaScript, so that I don't have to use <code>time.toString().toTime()</code>?</p>
  
  <p>Thanks!</p>