Search code examples
swiftpropertiesnsnumberformatter

NSNumberFormatter inside a computed Property


i am trying to format a string to a number with NSNumberFormatter. My code looks like this:

var displayValue: Double? {
    get {
        let i = "4.2"
        return NSNumberFormatter().numberFromString(i)?.doubleValue
    }
}

The property is always nil, what am i missing?


Solution

  • Martin R! is right it was a locale issue "4,2" works fine, thanks!