Strange behavior creating Double from String on Mac and Linux


(Krystof Beuermann) #1

Hi Guys,

i just stumbled over this different behavior between Mac and Linux:

MacOS Sierra 10.12.1 Swift 3.0.2 REPL

1> import Foundation
2. let nf = NumberFormatter()
3. print(nf.string(for: (Double("1")?.rounded()) as Any) as Any)
4. print(nf.string(for: (Double("1")!.rounded()) as Any) as Any)

Optional("1")
Optional("1")

On Linux (http://swiftlang.ng.bluemix.net/#/repl/5876ac525784322e15d09920) the same code prints

nil
Optional("1“)

Is this a feature or a bug? Can anyone explain this?

Thanks for you help!

Krystof Beuermann