I can't convert string to double correctly.
I tried to convert string to double, but I couldn't convert it correctly and didn't know what the problem was.
- OS : MacOS 12.6
- CPU : Apple M1
- Xcode : Version 14.0.1
how to convert string to double in swift
I can't convert string to double correctly.
I tried to convert string to double, but I couldn't convert it correctly and didn't know what the problem was.
how to convert string to double in swift
 
    
    String is converting successfully but it is giving you approximate value based on value in String.
instead of doubleVlaue use Double initializer to convert string
Double(myString)
it will return you an option double. If the string contains invalid characters or invalid format it will return nil.
you can unwrap it like this
 if let convertedValue = Double(myString) {
    print("Value is \(convertedValue)")
} else {
    print("Not a valid number")
}
