Mac Swift 3 Nsnumberformatter issue

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
280
86
I just converter project to swift 3 and now I'm having errors with numberformatter

i tried the following and they all don't work anymore

Code:
let result = 123.456
let numberFormatter: NumberFormatter = NumberFormatter()
numberFormatter.groupingSeparator = ","
numberFormatter.groupingSize = 3
numberFormatter.usesGroupingSeparator = true
numberFormatter.decimalSeparator = "."
numberFormatter.numberStyle = NumberFormatter.Style.decimal
numberFormatter.minimumFractionDigits = 15
let theString: String = numberFormatter.stringFromNumber((result))! // i get error cannot convert value of type double to expected argument type 'NSNumber'

let theString: String = numberFormatter.stringFromNumber((NSNumber(result)))! // changed it to this and i get error "Argument labels '(_:)' do not match any available overloads"

let theString = numberFormatter.stringFromNumber((NSNumber(result)))! // changed it to this with same error
not sure what to do anymore, i looked everywhere and there are no guides for swift 3 number formatter
 

MirekEl

macrumors newbie
Dec 1, 2015
24
42
If I recall correctly, the function is now called string, not stringWithNumber
 

anheca68

macrumors newbie
Apr 6, 2017
1
0
I just converter project to swift 3 and now I'm having errors with numberformatter

i tried the following and they all don't work anymore

Code:
let result = 123.456
let numberFormatter: NumberFormatter = NumberFormatter()
numberFormatter.groupingSeparator = ","
numberFormatter.groupingSize = 3
numberFormatter.usesGroupingSeparator = true
numberFormatter.decimalSeparator = "."
numberFormatter.numberStyle = NumberFormatter.Style.decimal
numberFormatter.minimumFractionDigits = 15
let theString: String = numberFormatter.stringFromNumber((result))! // i get error cannot convert value of type double to expected argument type 'NSNumber'

let theString: String = numberFormatter.stringFromNumber((NSNumber(result)))! // changed it to this and i get error "Argument labels '(_:)' do not match any available overloads"

let theString = numberFormatter.stringFromNumber((NSNumber(result)))! // changed it to this with same error
not sure what to do anymore, i looked everywhere and there are no guides for swift 3 number formatter
[doublepost=1491510615][/doublepost]con las modificaciones en swift 3.0 tu código debería de funcionar de la siguiente manera ..... slds
let theString: String = numberFormatter.string(from: (NSNumber(value: result)))!
 

spiffers

Suspended
Apr 12, 2009
105
88
Code:
let result: NSNumber = 123.456 // Set the varible to be of type NSNumber
let numberFormatter: NumberFormatter = NumberFormatter()
numberFormatter.groupingSeparator = ","
numberFormatter.groupingSize = 3
numberFormatter.usesGroupingSeparator = true
numberFormatter.decimalSeparator = "."
numberFormatter.numberStyle = NumberFormatter.Style.decimal
numberFormatter.minimumFractionDigits = 15

let theString: String = numberFormatter.string(from: result)! // And here you use the new API, numberFormatter.string(from:)
 

Similar threads

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.