I want unformat string back into the number
If with USD all works from the box with accounting library, but for example for russian ruble it fails.
String examples are 1,00 руб. (RUB)
and $20.00 (USD)
So, I could parse those string and get currency code (in case I might need to provide it to the library) with for example this code:
I tried accounting and numbro libraries
// getting currency code
let init = (data.orderAmount).indexOf('(')
let fin = (data.orderAmount).indexOf(')')
console.log(data.orderAmount).substr(init + 1, fin - init - 1)
If I for example pass 1,00 руб. (RUB)
into the accounting.unformat I would get 100
instead of 1
, but for usd example it would work and result would produce 20
. Same result with numbro, only need to also remove part in ()
in that case.
What I really want is solution, where I could pass currency code and string, and get correct number from the string for the given currency.
I tried globalize library numberParser
and currencyFormatter
without any success