scurker / currency.js

A javascript library for handling currencies

Home Page:https://currency.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identify separator and decimal.

gj84 opened this issue · comments

I'm working on a piece of software in which users input different currency values as they use them (at least european and anglo ways):

"123,456,783.14"
"123.456.783,14"
"123 456 783,14"
"123456783.14"

(and so on)

Sometimes use '.' as a decimal, sometimes ',' etc.
All of them seem to be perfect currency values, even though we have to identify decimal value, and the rest spring by its own.

So is there some way to auto detect which one is decimal separator and which one is thousand separator without knowing it before?

I mean:

currency('123.453,14').someMagic() // --> {separator: '.', decimal: ','}

//or
currency('123.453,14').autoMagic().value
123453.14