title: In Swift how do I display a percentage value rounded up or down with no decimal places
body: <p>I thought this would be fairly straightforward, but I can't seem to work it out or find an existing question that's covers my situation.</p>
  
  <p>Originally I set up a number of variables as follows:</p>
  
  <pre><code>var score :Int! = 0
  var totalquestionsasked :Int! = 0
  var percentagecorrect :Int! = 0
  </code></pre>
  
  <p>This got all my values calculating okay, but I ran into problems with the percentage.</p>
  
  <p>My basic formula for the percentage is:</p>
  
  <pre><code>percentagecorrect = score / totalquestionsasked * 100
  </code></pre>
  
  <p>However, I couldn't get this to display when using the value in a text label.</p>
  
  <p>So after some research, I changed my variables to this instead:</p>
  
  <pre><code>var score :Double = 0.0
  var totalquestionsasked :Double = 0.0
  var percentagecorrect :Double = 0.0
  </code></pre>
  
  <p>And still used the same formula for the percentage:</p>
  
  <pre><code>percentagecorrect = score / totalquestionsasked * 100
  </code></pre>
  
  <p>However, while this displayed okay, I didn't want all the decimal places. So after some more research I came across an extension in another question and adapted it for my application. My extension is:</p>
  
  <pre><code>extension Double {
      var roundTo0f: Double {return Double(round(1*self)/1) }
      var roundTo1f: Double {return Double(round(10*self)/10) }
      var roundTo2f: Double {return Double(round(100*self)/100)  }
      var roundTo3f: Double {return Double(round(1000*self)/1000) }
  }
  </code></pre>
  
  <p>And I've tried using the extension as follows:</p>
  
  <pre><code>percentagecorrect = score / totalquestionsasked * 100
  let percentagevalue: Double = percentagecorrect.roundTo0f
  labelPercent.text = "\(percentagevalue)"
  </code></pre>
  
  <p>The end result is that this is pretty close to what I want. However it does still display the percentage to 1 decimal place. <em>(As an aside, it's not accurate - what I mean is that if the score is 1 and the number of questions asked is 3, the above code displays the percentage as 33.0 instead of 33.3, but I digress)</em> </p>
  
  <p>What I'm actually wanting is the value to round up or down to the nearest whole number before displaying the value. In other words, what I want is</p>
  
  <ul>
  <li>if the value is 33.3 for it to round down to 33 and display as 33</li>
  <li>if the value is 66.6 for it to round up to 67 and display as 67</li>
  </ul>
  
  <p>That is I want no decimal places at all in the displayed result. At present, it rounds up/down correctly but sill displays ".0" at the end. If this isn't possible, then I want it to display to one decimal place correctly.</p>
  
  <p>I am new to programming and Swift is the first language I'm trying to learn, so maybe this is just a newbie mistake, but I really can't find what I'm doing wrong.</p>
  
  <p>How do I get this to work?</p>