DEV Community

Discussion on: Daily Challenge #276 - Unwanted Dollar Signs

Collapse
 
cr0wst profile image
Steve Crow

Here's Kotlin with a String extension function:

fun String.toMoneyValue() =
    this.filter { it.isDigit() || it in listOf('-', '.') }
        .toBigDecimal()

// Examples
"12.34".toMoneyValue()
"-0.89".toMoneyValue()
".11".toMoneyValue()
"007".toMoneyValue()