title: Swift: find out how many digits an integer has
body: <p>I don't have the right English or math vocabulary to really explain what I want to do, but I'll try to explain. Basically I want to figure out &quot;how big&quot; an integer is, how many decimal positions it has. For example 1234 is &quot;a thousand&quot; number, and 2,987,123 is &quot;a million&quot; number.</p>
  <p>I can do something like this, but that is rather silly :)</p>
  <pre><code>extension Int {
    func size() -&gt; Int {
      switch self {
      case 0...99:
        return 10
  
      case 100...999:
        return 100
  
      case 1000...9999:
        return 1000
  
      case 10000...99999:
        return 10000
  
      case 100000...999999:
        return 100000
  
      case 1000000...9999999:
        return 1000000
  
      default:
        return 0 // where do we stop?
      }
    }
  }
  </code></pre>