Hi decimal separator is not comma but dot (.)

You can replace comma with dot before parsing

val newPrice = price.replace(",", ".")

UPDATE: Also you can use custom symbols for parsing

fun parse(decimal: String): Number? {
    val symbols = DecimalFormatSymbols().apply {
        decimalSeparator = ','
        groupingSeparator = ' '
    }
    val df = DecimalFormat().apply {
        decimalFormatSymbols = symbols
    }
    
    return try {
         df.parse(decimal) ?: 0
     } catch (ex: ParseException){
         0
     }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top