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

formatNumber does not support custom decimal? #129

Open tofdragon opened 8 years ago

tofdragon commented 8 years ago

source: var formatNumber = lib.formatNumber = lib.format = function(number, precision, thousand, decimal) { ....................... number = unformat(number); ....................... }

Why don't unformat passing parameters to a decimal? unformat(number, decimal) ? decimal Is not equal to . 。There will be a problem

Lakshmi-Sharma commented 8 years ago

@tofdragon If you want to use a different decimal value, use settings:

accounting.settings = { number: { decimal: "*"}}

and then, when you do

accounting.unformat(123*456) = 123.456

Use the accouting.js file instead of the accounting.min.js There seems to be some issue with the accounting.min.js, it does not handle this correctly

tofdragon commented 8 years ago

@Lakshmi-Sharma Thank you for your advice

I have to modify the source code to

var formatNumber = lib.formatNumber = lib.format = function(number, precision, thousand, decimal) { ....................... //add decimal parameter number = unformat(number, decimal); ....................... }

The basic test is normal。But don't know how the author's intention, don't know is a bug, or the authors have other meanings

Lakshmi-Sharma commented 8 years ago

@tofdragon If you change it in the settings, you shouldn't have to add it as a parameter.

tofdragon commented 8 years ago

@Lakshmi-Sharma This is a global, in a page will have multiple influence each other

pycarlson commented 6 years ago

https://github.com/openexchangerates/accounting.js/pull/183