title: Change Time Conversion Function to Swift Extension
body: <p>I have a function that converts minutes to either a decimal or a HH:MM string based on a user preference in <code>NSUserDefaults</code>.</p>
  
  <p>For example, <code>90</code> minutes would be either <code>1.5</code> or <code>1:30</code>.</p>
  
  <p>Here's my function:</p>
  
  <pre><code>func decimalOrHHMM(value:Int) -&gt; String{
    let totalMinutes = Double(value)
  
    let defaults = UserDefaults.standard
    if defaults.string(forKey: "displayTotalsAs") == "hhmm"{
      //HH:MM
      let hours = floor(totalMinutes/60)
      let minutes = totalMinutes.truncatingRemainder(dividingBy: 60) //This gives us the remainder
      let hrs = String(format: "%.0f", hours) //Remove tenths place
      var mins = ""
      if minutes &lt; 10{
        //Prepend 0
        mins = String(format: "0%.0f", minutes)
      }else{
        mins = String(format: "%.0f", minutes)
      }
      return "\(hrs):\(mins)"
    }else{
      //Decimal
      return String(format: "%.1f", totalMinutes/60)
    }
  }
  </code></pre>
  
  <p>This works great, but I'm wondering if this can be converted to an <code>NSNumberFormatter</code> Swift extension somehow. I'm having trouble knowing what I need to override in order to do all the converting.</p>
  
  <p>Any idea how I can make this an extension?</p>