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.95k stars 528 forks source link

Unformat not respecting settings #175

Open enclle opened 7 years ago

enclle commented 7 years ago

I'm brazilian, here in Brazil we use "," as decimal separator, "." as thousand separator and "R$" as currency symbol. I have some text input with formatted input, like "R$ 123,45", then I call unformat(text) to set the (double) value and the result as expected would be (doube) 123.45, but the actual result is (double) 12345.

The accounting.settings is:

accounting.settings = { currency: { symbol : "R$", format: "%s%v", decimal : ",",
thousand: ".", precision : 2
}, number: { precision : 0, thousand: ".", decimal : "," } }

enclle commented 7 years ago

As a temporary fix I do: unformat(text.replace(",","."))

fauresco commented 7 years ago

I'm also from Brazil and had the same issue.

I was about to try to fix the issue myself, debugging the unminified version of the library but, it turns out that the unminified version works just fine!

The dev must check the provided minified version for download, it seems to be outdated.

While this doesn't happen, we can just grab the unminified version, add to our projects and run some minification process ourselves.

ram-nadella commented 6 years ago

We just ran into this issue and the solution @fauresco is proposing is the way to go for the time being. The unformat logic in the non-minified version of the file works as expected.

Looks like the minified and non-minified files have diverged quite a bit, I see updated 2 years ago vs 6 months ago in the commit history.

juanca commented 6 years ago

We ran into the same issue and are proposing this solution: https://github.com/openexchangerates/accounting.js/pull/183