Last active
May 1, 2022 23:29
-
-
Save fitomad/6501770c0f67ec0d03e00ac22efba4c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Convierte un `String` en `Double` | |
Si no se puede convertir se devuelve 0.0 | |
*/ | |
func double(from string: String) -> Double | |
{ | |
let formatter = NumberFormatter(); | |
formatter.locale = Locale(identifier: "es_ES") | |
formatter.numberStyle = .decimal | |
formatter.thousandSeparator = "." | |
formatter.decimalSeparator = "," | |
return formatter.number(from: string)?.doubleValue ?? 0.0 | |
} | |
// Podemos pasar una función... | |
frame2021.transformColumn("LATITUD", double(from:)) | |
// ...o en el trailing clouse. | |
frame2021.transformColumn("LONGITUD") { (value: String) -> Double in | |
let formatter = NumberFormatter(); | |
formatter.locale = Locale(identifier: "es_ES") | |
formatter.numberStyle = .decimal | |
formatter.thousandSeparator = "." | |
formatter.decimalSeparator = "," | |
return formatter.number(from: value)?.doubleValue ?? 0.0 | |
} | |
// Convertimos la columna PEATONES de String a Int | |
frame2021.transformColumn("PEATONES") { (value: String) -> Int in | |
let formatter = NumberFormatter(); | |
formatter.locale = Locale(identifier: "es_ES") | |
formatter.numberStyle = .decimal | |
formatter.thousandSeparator = "." | |
return formatter.number(from: value)?.intValue ?? 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment