openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.96k stars 530 forks source link

error when unformat whith decimal point #48

Closed ekubyshin closed 12 years ago

ekubyshin commented 12 years ago

try to unformat number '1 000.22':

unformat('1 000.22', ',')

and result is: 100012

ekubyshin commented 12 years ago

error is in this regExp new RegExp("[^0-9-" + decimal + "]", ["g"])

wjcrowcroft commented 12 years ago

That's probably because you're specifying that the decimal separator to look for is a ","

Try: unformat('1 000.22', '.')

ekubyshin commented 12 years ago

need to check that the value contains only one delimiter. it's bug

ekubyshin commented 12 years ago

how about this? unformat('11111,22') result is: 1111122

wjcrowcroft commented 12 years ago

This is expected behaviour

Try:

accounting.unformat("$ 1,000.99") // 1000.99
accounting.unformat("$ 1.000,99", ",") // 1000.99