title: How to separate thousands from a Float value with decimals in Swift
body: <p>I have the following Float: <code>1123455432.67899</code></p>
  
  <p>My desired result is a String: <code>1,123,455,432.67899</code></p>
  
  <p>Best case correct <code>,</code> and <code>.</code> based on location (US/Europe)</p>
  
  <pre><code>struct Number {
      static let withSeparator: NumberFormatter = {
          let formatter = NumberFormatter()
          formatter.groupingSeparator = ","
          formatter.numberStyle = .decimal
          return formatter
      }()
  }
  
  let myFloat: Float = 1123455432.67899
  let myNumber = NSNumber(value: myFloat)
  let formatter = Number.withSeparator
  if let result = formatter.string(from: myNumber) {
     print(result)
  }
  </code></pre>
  
  <p>This formatter works great as long as my Float has no decimals, als soon as I'm having decimals it starts to "calculate". It calculates up/down based on the 3rd decimal number.</p>
  
  <p>What am I missing? What's the best way to get a <code>String: 1,123,455,432.67899</code> from a <code>Float</code> with no matter how many decimal numbers? Help is very appreciated.</p>
  
  <p>Edit:</p>
  
  <p>My exact function: </p>
  
  <pre><code>func formatValue(_ value: String ) -&gt; String {
  
      if let double = Double(value) {
  
          let formatter = Number.withSeparator
          if let result = formatter.string(from: NSNumber(value: double)) {
              return result
          } else {
              return value
          }
      } else {
          return value
      }
  }
  </code></pre>
  
  <p><code>value</code> is always a number for example <code>5.5555555555</code>. But in this specific case the <code>result = 5.556</code>.</p>