I try to convert a String into a NSDecimalNumber here it my code:
class func stringToDecimal (dataToDecimal: String) -> NSDecimalNumber {
let dataToDecimal = dataToDecimal.stringByReplacingOccurrencesOfString(",", withString: ".")
print(dataToDecimal)
let decimalReturn = NSDecimalNumber(string: dataToDecimal)
print(decimalReturn)
if decimalReturn == NSDecimalNumber.notANumber(){
return 0.00
}
return decimalReturn
}
First I thought that maybe the , is wrong but even with . it doesn't work. The first print (before converting) shows e.g 80,00 but the print(decimalReturn) shows only 80
the if line is the just to check if the result is not a number.
let dataToDecimal = dataToDecimal.stringByReplacingOccurrencesOfString(",", withString: ".")
first, to bring my string to get not nil. If I just try a string with a "," it will bring nil as result. – Guidepost