Skip to content

Commit

Permalink
Always parse numbers in US locales
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 17, 2023
1 parent 0711c2c commit 7986998
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ private fun parsePositiveDouble(string: String): Double? {
.replace(" ", ".")
.filter { it.isDigit() || it == '.' }

val numberFormat = NumberFormat.getInstance(Locale.getDefault())
val numberFormat = NumberFormat.getInstance(Locale.US)
if (numberFormat is DecimalFormat) {
try {
numberFormat.applyPattern("#,###.##")
val parsedNumber = numberFormat.parse(cleanedString)?.toDouble()
if (parsedNumber != null) return parsedNumber
if (parsedNumber != null) {
return parsedNumber
}
} catch (e: Exception) {
// ignored
}
}

return cleanedString.toDoubleOrNull() ?: string.toDoubleOrNull()
}

// endregion

fun parseTransactionType(
Expand Down

0 comments on commit 7986998

Please sign in to comment.