NSNumberFormatter inside a computed Property

60 views Asked by At

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?

1

There are 1 answers

0
www40 On BEST ANSWER

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