Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
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
 
If I recall correctly, the function is now called string, not stringWithNumber
 
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)))!
 
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:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.