title: Count amount of decimal places (Swift)
body: <p>I want to round a Double to a specific amount of decimal places.
  I want it to be rounded to the exact length of itself.</p>
  
  <p>For example "1.23" should stay "1.23", "1.230" instead should change to "1.23" etc.</p>
  
  <p>I am trying to count the decimal places and round the Double with that value.</p>
  
  <p>I've been trying around in Playground, but somehow Swift always rounds and uses unneeded decimal places.</p>
  
  <p>Here's what I got so far</p>
  
  <pre><code>var someDouble:Double
  var someString:String
  var lenghtInt:Int
  
  
  
  someDouble = 42.123                                 // create a float
  
  someDouble = someDouble % 1                         // get rid of everything infront of the comma
  
  someString = NSString(format: "%f", someDouble)     // format float into string
  
  lenghtInt = someString.utf16Count - 2               // count lenght, substract 2 (for "0" &amp; ".")
  </code></pre>
  
  <p>It tells me I have 6 decimal places because it puts "000" at the end.</p>
  
  <p>How do I fix this?</p>
  
  <p>By the way: </p>
  
  <p>Maybe I'm thinking completely wrong. The purpose of all of that is to display a Float/Double in a label but without the unneeded decimal places. It should work for any given number.
  Hopefully You guys have an answer for me! :)</p>
  
  <p>Thank You in advance</p>
  
  <p>Niklas</p>