简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM